Skip to content

Commit

Permalink
Merge pull request #38 from slope-it/php-8.2-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
asprega committed May 19, 2023
2 parents 781248d + 310f378 commit dda085e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/vendor
phpunit.xml
composer.lock
.phpunit.result.cache
.phpunit.cache/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 7 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
bootstrap="vendor/autoload.php"
processIsolation="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 16 additions & 4 deletions src/ClockMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand All @@ -123,19 +129,25 @@ 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);

if (extension_loaded('calendar')) {
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);
Expand Down
Empty file removed test
Empty file.
10 changes: 5 additions & 5 deletions tests/ClockMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 [
[
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit dda085e

Please sign in to comment.