Skip to content

Commit dda085e

Browse files
authored
Merge pull request #38 from slope-it/php-8.2-compat
2 parents 781248d + 310f378 commit dda085e

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
# - "7.4" Disabled due to https://github.com/composer/composer/issues/10387, which did not resolve the issue here somehow
1818
- "8.0"
1919
- "8.1"
20-
20+
- "8.2"
2121
steps:
2222
- name: "Checkout"
2323
uses: "actions/checkout@v2"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/vendor
33
phpunit.xml
44
composer.lock
5-
.phpunit.result.cache
5+
.phpunit.cache/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ Note that, as this is not a tool intended for production, it should be required
4343
- gettimeofday()
4444
- gmdate()
4545
- gmmktime()
46-
- gmstrftime()
46+
- gmstrftime() (DEPRECATED starting from PHP 8.1)
4747
- idate()
4848
- localtime()
4949
- microtime()
5050
- mktime()
51-
- strftime()
51+
- strftime() (DEPRECATED starting from PHP 8.1)
5252
- strtotime()
5353
- time()
5454
- unixtojd()

phpunit.xml.dist

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
colors="true"
4-
convertErrorsToExceptions="true"
5-
convertNoticesToExceptions="true"
6-
convertWarningsToExceptions="true"
74
bootstrap="vendor/autoload.php"
85
processIsolation="false"
9-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
10-
<testsuites>
11-
<testsuite name="Tests">
12-
<directory>tests</directory>
13-
</testsuite>
14-
</testsuites>
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
7+
cacheDirectory=".phpunit.cache">
8+
<testsuites>
9+
<testsuite name="Tests">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
1513
</phpunit>

src/ClockMock.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ public static function reset(): void
8686
uopz_unset_return('gettimeofday');
8787
uopz_unset_return('gmdate');
8888
uopz_unset_return('gmmktime');
89-
uopz_unset_return('gmstrftime');
9089
uopz_unset_return('idate');
9190
uopz_unset_return('localtime');
9291
uopz_unset_return('microtime');
9392
uopz_unset_return('mktime');
94-
uopz_unset_return('strftime');
9593
uopz_unset_return('strtotime');
9694
uopz_unset_return('time');
9795
uopz_unset_return(\DateTime::class, 'createFromFormat');
@@ -101,6 +99,14 @@ public static function reset(): void
10199
uopz_unset_return('unixtojd');
102100
}
103101

102+
// The following two are deprecated -- prepare for removal in PHP 9.0
103+
if (function_exists('gmstrftime')) {
104+
uopz_unset_return('gmstrftime');
105+
}
106+
if (function_exists('strftime')) {
107+
uopz_unset_return('strftime');
108+
}
109+
104110
uopz_unset_mock(\DateTime::class);
105111
uopz_unset_mock(\DateTimeImmutable::class);
106112

@@ -123,19 +129,25 @@ private static function activateMocksIfNeeded(): void
123129
uopz_set_return('gettimeofday', self::mock_gettimeofday(), true);
124130
uopz_set_return('gmdate', self::mock_gmdate(), true);
125131
uopz_set_return('gmmktime', self::mock_gmmktime(), true);
126-
uopz_set_return('gmstrftime', self::mock_gmstrftime(), true);
127132
uopz_set_return('idate', self::mock_idate(), true);
128133
uopz_set_return('localtime', self::mock_localtime(), true);
129134
uopz_set_return('microtime', self::mock_microtime(), true);
130135
uopz_set_return('mktime', self::mock_mktime(), true);
131-
uopz_set_return('strftime', self::mock_strftime(), true);
132136
uopz_set_return('strtotime', self::mock_strtotime(), true);
133137
uopz_set_return('time', self::mock_time(), true);
134138

135139
if (extension_loaded('calendar')) {
136140
uopz_set_return('unixtojd', self::mock_unixtojd(), true);
137141
}
138142

143+
// The following two are deprecated -- prepare for removal in PHP 9.0
144+
if (function_exists('gmstrftime')) {
145+
uopz_set_return('gmstrftime', self::mock_gmstrftime(), true);
146+
}
147+
if (function_exists('strftime')) {
148+
uopz_set_return('strftime', self::mock_strftime(), true);
149+
}
150+
139151
uopz_set_mock(\DateTime::class, DateTimeMock::class);
140152
uopz_set_return(\DateTime::class, 'createFromFormat', self::mock_date_create_from_format(), true);
141153
uopz_set_mock(\DateTimeImmutable::class, DateTimeImmutableMock::class);

test

Whitespace-only changes.

tests/ClockMockTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function test_getdate()
282282
);
283283
}
284284

285-
public function dataProvider_gettimeofday(): array
285+
public static function dataProvider_gettimeofday(): array
286286
{
287287
return [
288288
['2022-04-04 14:26:29.123456', 'UTC', [1649082389, 123456, 0, 0]],
@@ -323,7 +323,7 @@ public function test_gmstrftime()
323323
$this->assertEquals('2022-04-04 11:26:29', gmstrftime('%F %T'));
324324
}
325325

326-
public function dateProvider_gmmktime(): array
326+
public static function dataProvider_gmmktime(): array
327327
{
328328
// NOTE: for all datasets, hour in freezeDateTime is completely irrelevant because always overridden by $hour
329329
// 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
368368
}
369369

370370
/**
371-
* @dataProvider dateProvider_gmmktime
371+
* @dataProvider dataProvider_gmmktime
372372
*/
373373
public function test_gmmktime(string $freezeDateTime, array $mktimeArgs, string $expectedDateTime)
374374
{
@@ -443,7 +443,7 @@ public function test_strftime()
443443
$this->assertEquals('2022-04-04 14:26:29', strftime('%F %T'));
444444
}
445445

446-
public function dateProvider_mktime(): array
446+
public static function dataProvider_mktime(): array
447447
{
448448
return [
449449
[
@@ -485,7 +485,7 @@ public function dateProvider_mktime(): array
485485
}
486486

487487
/**
488-
* @dataProvider dateProvider_mktime
488+
* @dataProvider dataProvider_mktime
489489
*/
490490
public function test_mktime(string $freezeDateTime, array $mktimeArgs, string $expectedDateTime)
491491
{

0 commit comments

Comments
 (0)