diff --git a/composer.json b/composer.json index 25d4ee34..58b4792e 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "require-dev": { "cakephp/cakephp-codesniffer": "^5.0", - "phpunit/phpunit": "^10.1.0 || ^11.1.3" + "phpunit/phpunit": "^10.5.58 || ^11.1.3" }, "provide": { "psr/clock-implementation": "1.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b39ef802..35b373a4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,9 @@ + colors="true" + failOnDeprecation="true" + displayDetailsOnTestsThatTriggerDeprecations="true"> tests @@ -13,4 +15,9 @@ src/ + + + + + diff --git a/src/Chronos.php b/src/Chronos.php index a46f1d39..a74bfb65 100644 --- a/src/Chronos.php +++ b/src/Chronos.php @@ -2587,6 +2587,17 @@ public function diffForHumans(?DateTimeInterface $other = null, bool $absolute = return static::diffFormatter()->diffForHumans($this, $other, $absolute); } + /** + * Converts the time zone to UTC and returns a string in RFC7231 format. + * This replaced the deprecated and broken ``DATE_RFC7231`` formatting constant. + * + * @return string + */ + public function toRfc7231String(): string + { + return $this->setTimezone('UTC')->format('D, d M Y H:i:s \G\M\T'); + } + /** * Returns a DateTimeImmutable instance * diff --git a/tests/TestCase/DateTime/StringsTest.php b/tests/TestCase/DateTime/StringsTest.php index 72d0b741..a4a48502 100644 --- a/tests/TestCase/DateTime/StringsTest.php +++ b/tests/TestCase/DateTime/StringsTest.php @@ -160,6 +160,12 @@ public function testToUnixString() $this->assertSame('1639224001', $time->toUnixString()); } + public function testToRfc7231String() + { + $time = Chronos::parse('2014-04-20 08:00:00', 'America/Toronto'); + $this->assertSame('Sun, 20 Apr 2014 12:00:00 GMT', $time->toRfc7231String()); + } + /** * Provides values and expectations for the toQuarter method * @@ -171,10 +177,6 @@ public static function toQuarterProvider() ['2007-12-25', 4], ['2007-9-25', 3], ['2007-3-25', 1], - ['2007-3-25', ['2007-01-01', '2007-03-31'], true], - ['2007-5-25', ['2007-04-01', '2007-06-30'], true], - ['2007-8-25', ['2007-07-01', '2007-09-30'], true], - ['2007-12-25', ['2007-10-01', '2007-12-31'], true], ]; } @@ -186,7 +188,26 @@ public static function toQuarterProvider() #[DataProvider('toQuarterProvider')] public function testToQuarter($date, $expected, $range = false) { - $this->assertSame($expected, (new Chronos($date))->toQuarter($range)); + $this->assertSame($expected, (new Chronos($date))->toQuarter()); + } + + public static function toQuarterRangeProvider() + { + return [ + ['2007-3-25', ['2007-01-01', '2007-03-31']], + ['2007-5-25', ['2007-04-01', '2007-06-30']], + ['2007-8-25', ['2007-07-01', '2007-09-30']], + ['2007-12-25', ['2007-10-01', '2007-12-31']], + ]; + } + + #[DataProvider('toQuarterRangeProvider')] + public function testToQuarterRange($date, $expected) + { + $this->assertSame($expected, (new Chronos($date))->toQuarterRange()); + $this->deprecated(function() use ($date, $expected) { + $this->assertSame($expected, (new Chronos($date))->toQuarter(true)); + }); } /**