diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9200386..9d9de87 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: # - "7.4" Disabled due to https://github.com/composer/composer/issues/10387, which did not resolve the issue here somehow - "8.0" - "8.1" - + - "8.2" steps: - name: "Checkout" uses: "actions/checkout@v2" diff --git a/.gitignore b/.gitignore index 82b50a4..cb6917c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /vendor phpunit.xml composer.lock -.phpunit.result.cache +.phpunit.cache/ diff --git a/README.md b/README.md index a48ef3d..f0c8bbb 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ Note that, as this is not a tool intended for production, it should be required - gettimeofday() - gmdate() - gmmktime() -- gmstrftime() +- gmstrftime() (DEPRECATED starting from PHP 8.1) - idate() - localtime() - microtime() - mktime() -- strftime() +- strftime() (DEPRECATED starting from PHP 8.1) - strtotime() - time() - unixtojd() diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4420dee..19ef876 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,13 @@ - - - tests - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" + cacheDirectory=".phpunit.cache"> + + + tests + + diff --git a/src/ClockMock.php b/src/ClockMock.php index 740ccb8..a53cff2 100644 --- a/src/ClockMock.php +++ b/src/ClockMock.php @@ -86,12 +86,10 @@ public static function reset(): void uopz_unset_return('gettimeofday'); uopz_unset_return('gmdate'); uopz_unset_return('gmmktime'); - uopz_unset_return('gmstrftime'); uopz_unset_return('idate'); uopz_unset_return('localtime'); uopz_unset_return('microtime'); uopz_unset_return('mktime'); - uopz_unset_return('strftime'); uopz_unset_return('strtotime'); uopz_unset_return('time'); uopz_unset_return(\DateTime::class, 'createFromFormat'); @@ -101,6 +99,14 @@ public static function reset(): void uopz_unset_return('unixtojd'); } + // The following two are deprecated -- prepare for removal in PHP 9.0 + if (function_exists('gmstrftime')) { + uopz_unset_return('gmstrftime'); + } + if (function_exists('strftime')) { + uopz_unset_return('strftime'); + } + uopz_unset_mock(\DateTime::class); uopz_unset_mock(\DateTimeImmutable::class); @@ -123,12 +129,10 @@ private static function activateMocksIfNeeded(): void uopz_set_return('gettimeofday', self::mock_gettimeofday(), true); uopz_set_return('gmdate', self::mock_gmdate(), true); uopz_set_return('gmmktime', self::mock_gmmktime(), true); - uopz_set_return('gmstrftime', self::mock_gmstrftime(), true); uopz_set_return('idate', self::mock_idate(), true); uopz_set_return('localtime', self::mock_localtime(), true); uopz_set_return('microtime', self::mock_microtime(), true); uopz_set_return('mktime', self::mock_mktime(), true); - uopz_set_return('strftime', self::mock_strftime(), true); uopz_set_return('strtotime', self::mock_strtotime(), true); uopz_set_return('time', self::mock_time(), true); @@ -136,6 +140,14 @@ private static function activateMocksIfNeeded(): void uopz_set_return('unixtojd', self::mock_unixtojd(), true); } + // The following two are deprecated -- prepare for removal in PHP 9.0 + if (function_exists('gmstrftime')) { + uopz_set_return('gmstrftime', self::mock_gmstrftime(), true); + } + if (function_exists('strftime')) { + uopz_set_return('strftime', self::mock_strftime(), true); + } + uopz_set_mock(\DateTime::class, DateTimeMock::class); uopz_set_return(\DateTime::class, 'createFromFormat', self::mock_date_create_from_format(), true); uopz_set_mock(\DateTimeImmutable::class, DateTimeImmutableMock::class); diff --git a/test b/test deleted file mode 100644 index e69de29..0000000 diff --git a/tests/ClockMockTest.php b/tests/ClockMockTest.php index c4d4c35..c835a4a 100644 --- a/tests/ClockMockTest.php +++ b/tests/ClockMockTest.php @@ -282,7 +282,7 @@ public function test_getdate() ); } - public function dataProvider_gettimeofday(): array + public static function dataProvider_gettimeofday(): array { return [ ['2022-04-04 14:26:29.123456', 'UTC', [1649082389, 123456, 0, 0]], @@ -323,7 +323,7 @@ public function test_gmstrftime() $this->assertEquals('2022-04-04 11:26:29', gmstrftime('%F %T')); } - public function dateProvider_gmmktime(): array + public static function dataProvider_gmmktime(): array { // NOTE: for all datasets, hour in freezeDateTime is completely irrelevant because always overridden by $hour // parameter provided to gmmktime. Also, in expectedDateTime hour is always "13" because hour 10 in GMT @@ -368,7 +368,7 @@ public function dateProvider_gmmktime(): array } /** - * @dataProvider dateProvider_gmmktime + * @dataProvider dataProvider_gmmktime */ public function test_gmmktime(string $freezeDateTime, array $mktimeArgs, string $expectedDateTime) { @@ -443,7 +443,7 @@ public function test_strftime() $this->assertEquals('2022-04-04 14:26:29', strftime('%F %T')); } - public function dateProvider_mktime(): array + public static function dataProvider_mktime(): array { return [ [ @@ -485,7 +485,7 @@ public function dateProvider_mktime(): array } /** - * @dataProvider dateProvider_mktime + * @dataProvider dataProvider_mktime */ public function test_mktime(string $freezeDateTime, array $mktimeArgs, string $expectedDateTime) {