Skip to content

Commit 253c754

Browse files
authored
Update test suite to supports PHP8.3 (#354)
Update package to work in PHP8.3
1 parent 43bddff commit 253c754

File tree

8 files changed

+67
-61
lines changed

8 files changed

+67
-61
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-20.04
1111
strategy:
1212
matrix:
13-
php: ['8.1', '8.2']
13+
php: ['8.1', '8.2', '8.3']
1414
stability: [prefer-lowest, prefer-stable]
1515
steps:
1616
- name: Checkout code
@@ -52,4 +52,4 @@ jobs:
5252

5353
- name: Run Coding style rules
5454
run: composer phpcs:fix
55-
if: ${{ matrix.php == '8.1' && matrix.stability == 'prefer-stable'}}
55+
if: ${{ matrix.php == '8.2' && matrix.stability == 'prefer-stable'}}

.php-cs-fixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'import_functions' => true,
1818
],
1919
'list_syntax' => ['syntax' => 'short'],
20-
'new_with_braces' => true,
20+
'new_with_parentheses' => true,
2121
'no_blank_lines_after_phpdoc' => true,
2222
'no_empty_phpdoc' => true,
2323
'no_empty_comment' => true,
@@ -39,7 +39,7 @@
3939
'phpdoc_summary' => true,
4040
'psr_autoloading' => true,
4141
'return_type_declaration' => ['space_before' => 'none'],
42-
'single_blank_line_before_namespace' => true,
42+
'blank_lines_before_namespace' => true,
4343
'single_quote' => true,
4444
'space_after_semicolon' => true,
4545
'ternary_operator_spaces' => true,

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@
4646
"ext-json": "*"
4747
},
4848
"require-dev": {
49-
"friendsofphp/php-cs-fixer": "^v3.13.2",
50-
"guzzlehttp/guzzle": "^7.5",
51-
"guzzlehttp/psr7": "^1.6 || ^2.4.3",
52-
"phpstan/phpstan": "^1.10.3",
53-
"phpstan/phpstan-phpunit": "^1.3.8",
54-
"phpstan/phpstan-strict-rules": "^1.5.0",
55-
"phpunit/phpunit": "^10.0.12",
56-
"psr/http-factory": "^1.0.1",
49+
"friendsofphp/php-cs-fixer": "^v3.35.1",
50+
"guzzlehttp/guzzle": "^7.8",
51+
"guzzlehttp/psr7": "^1.6 || ^2.6.1",
52+
"phpstan/phpstan": "^1.10.39",
53+
"phpstan/phpstan-phpunit": "^1.3.15",
54+
"phpstan/phpstan-strict-rules": "^1.5.1",
55+
"phpunit/phpunit": "^10.4.1",
56+
"psr/http-factory": "^1.0.2",
5757
"psr/simple-cache": "^1.0.1",
58-
"symfony/cache": "^v5.0.0 || ^v6.0.0"
58+
"symfony/cache": "^v5.0.0 || ^v6.3.5"
5959
},
6060
"suggest": {
6161
"psr/http-client-implementation": "To use the storage functionnality which depends on PSR-18",
@@ -71,7 +71,7 @@
7171
"scripts": {
7272
"phpcs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
7373
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
74-
"phpstan": "phpstan analyse -l max -c phpstan.neon src --xdebug --memory-limit=256M --ansi",
74+
"phpstan": "phpstan analyse -l max -c phpstan.neon src --memory-limit=256M --ansi",
7575
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
7676
"test": [
7777
"@phpunit",

phpunit.xml.dist

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
5-
bootstrap="vendor/autoload.php"
6-
backupGlobals="false"
7-
colors="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
cacheDirectory=".phpunit.cache"
11-
backupStaticProperties="false"
12-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
133
<coverage>
14-
<include>
15-
<directory suffix=".php">src</directory>
16-
</include>
17-
<exclude>
18-
<directory suffix="Test.php">src</directory>
19-
</exclude>
204
<report>
215
<clover outputFile="build/clover.xml"/>
226
<html outputDirectory="build/coverage"/>
@@ -31,4 +15,12 @@
3115
<logging>
3216
<junit outputFile="build/junit.xml"/>
3317
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src</directory>
21+
</include>
22+
<exclude>
23+
<directory suffix="Test.php">src</directory>
24+
</exclude>
25+
</source>
3426
</phpunit>

src/Storage/PsrStorageFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ final class PsrStorageFactoryTest extends TestCase
1515

1616
public function setUp(): void
1717
{
18-
$cache = $this->createStub(CacheInterface::class);
19-
$requestFactory = $this->createStub(RequestFactoryInterface::class);
20-
$client = $this->createStub(ClientInterface::class);
18+
$cache = self::createStub(CacheInterface::class);
19+
$requestFactory = self::createStub(RequestFactoryInterface::class);
20+
$client = self::createStub(ClientInterface::class);
2121

2222
$this->factory = new PsrStorageFactory($cache, $client, $requestFactory);
2323
}

src/Storage/PublicSuffixListPsr16CacheTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class PublicSuffixListPsr16CacheTest extends TestCase
1818
{
1919
public function testItReturnsNullIfTheCacheDoesNotExists(): void
2020
{
21-
$cache = $this->createStub(CacheInterface::class);
21+
$cache = self::createStub(CacheInterface::class);
2222
$cache->method('get')->willReturn(null);
2323

2424
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', '1 DAY');
@@ -29,7 +29,7 @@ public function testItReturnsNullIfTheCacheDoesNotExists(): void
2929
public function testItReturnsAnInstanceIfTheCorrectCacheExists(): void
3030
{
3131
$rules = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
32-
$cache = $this->createStub(CacheInterface::class);
32+
$cache = self::createStub(CacheInterface::class);
3333
$cache->method('get')->willReturn($rules);
3434

3535
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', 86400);
@@ -39,7 +39,7 @@ public function testItReturnsAnInstanceIfTheCorrectCacheExists(): void
3939

4040
public function testItReturnsNullIfTheCacheContentContainsInvalidJsonData(): void
4141
{
42-
$cache = $this->createStub(CacheInterface::class);
42+
$cache = self::createStub(CacheInterface::class);
4343
$cache->method('get')->willReturn('foobar');
4444

4545
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', 86400);
@@ -48,7 +48,7 @@ public function testItReturnsNullIfTheCacheContentContainsInvalidJsonData(): voi
4848

4949
public function testItReturnsNullIfTheCacheContentCannotBeConvertedToTheCorrectInstance(): void
5050
{
51-
$cache = $this->createStub(CacheInterface::class);
51+
$cache = self::createStub(CacheInterface::class);
5252
$cache->method('get')->willReturn('{"foo":"bar"}');
5353

5454
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateTimeImmutable('+1 DAY'));
@@ -58,7 +58,7 @@ public function testItReturnsNullIfTheCacheContentCannotBeConvertedToTheCorrectI
5858

5959
public function testItCanStoreAPublicSuffixListInstance(): void
6060
{
61-
$cache = $this->createStub(CacheInterface::class);
61+
$cache = self::createStub(CacheInterface::class);
6262
$cache->method('set')->willReturn(true);
6363

6464
$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
@@ -69,7 +69,7 @@ public function testItCanStoreAPublicSuffixListInstance(): void
6969

7070
public function testItReturnsFalseIfItCantStoreAPublicSuffixListInstance(): void
7171
{
72-
$cache = $this->createStub(CacheInterface::class);
72+
$cache = self::createStub(CacheInterface::class);
7373
$cache->method('set')->willReturn(false);
7474

7575
$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
@@ -82,7 +82,7 @@ public function testItReturnsFalseIfItCantCacheAPublicSuffixListInstance(): void
8282
{
8383
$exception = new class('Something went wrong.', 0) extends RuntimeException implements CacheException {
8484
};
85-
$cache = $this->createStub(CacheInterface::class);
85+
$cache = self::createStub(CacheInterface::class);
8686
$cache->method('set')->will(self::throwException($exception));
8787

8888
$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
@@ -95,7 +95,7 @@ public function testItWillThrowIfItCantCacheAPublicSuffixListInstance(): void
9595
{
9696
$exception = new class('Something went wrong.', 0) extends RuntimeException {
9797
};
98-
$cache = $this->createStub(CacheInterface::class);
98+
$cache = self::createStub(CacheInterface::class);
9999
$cache->method('set')->will(self::throwException($exception));
100100

101101
$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
@@ -114,7 +114,7 @@ public function testItCanDeleteTheCachedDatabase(): void
114114
{
115115
$uri = 'http://www.example.com';
116116

117-
$cache = $this->createStub(CacheInterface::class);
117+
$cache = self::createStub(CacheInterface::class);
118118
$cache->method('delete')->willReturn(true);
119119

120120
$instance = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));
@@ -125,7 +125,7 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
125125
{
126126
$this->expectException(InvalidArgumentException::class);
127127

128-
$cache = $this->createStub(CacheInterface::class);
128+
$cache = self::createStub(CacheInterface::class);
129129
new PublicSuffixListPsr16Cache($cache, 'pdp_', 'foobar');
130130
}
131131
}

src/Storage/TimeToLive.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use DateTimeInterface;
1010
use InvalidArgumentException;
1111
use Stringable;
12+
use Throwable;
1213
use function filter_var;
1314
use const FILTER_VALIDATE_INT;
1415

@@ -19,13 +20,26 @@ final class TimeToLive
1920
{
2021
public static function fromDurationString(string $duration): DateInterval
2122
{
22-
set_error_handler(fn () => true);
23-
$interval = DateInterval::createFromDateString($duration);
24-
restore_error_handler();
25-
if (!$interval instanceof DateInterval) {
26-
throw new InvalidArgumentException(
27-
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.'
28-
);
23+
try {
24+
set_error_handler(fn () => true);
25+
$interval = DateInterval::createFromDateString($duration);
26+
restore_error_handler();
27+
if (!$interval instanceof DateInterval) {
28+
throw new InvalidArgumentException(
29+
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.'
30+
);
31+
}
32+
33+
} catch (Throwable $exception) {
34+
if (!$exception instanceof InvalidArgumentException) {
35+
throw new InvalidArgumentException(
36+
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.',
37+
0,
38+
$exception
39+
);
40+
}
41+
42+
throw $exception;
2943
}
3044

3145
return $interval;

src/Storage/TopLevelDomainListPsr16CacheTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class TopLevelDomainListPsr16CacheTest extends TestCase
1818
{
1919
public function testItReturnsNullIfTheCacheDoesNotExists(): void
2020
{
21-
$cache = $this->createStub(CacheInterface::class);
21+
$cache = self::createStub(CacheInterface::class);
2222
$cache->method('get')->willReturn(null);
2323

2424
$instance = new TopLevelDomainListPsr16Cache($cache, 'pdp_', '1 DAY');
@@ -29,7 +29,7 @@ public function testItReturnsNullIfTheCacheDoesNotExists(): void
2929
public function testItReturnsAnInstanceIfTheCorrectCacheExists(): void
3030
{
3131
$topLevelDomainList = TopLevelDomains::fromPath(dirname(__DIR__, 2).'/test_data/tlds-alpha-by-domain.txt');
32-
$cache = $this->createStub(CacheInterface::class);
32+
$cache = self::createStub(CacheInterface::class);
3333
$cache->method('get')->willReturn($topLevelDomainList);
3434

3535
$instance = new TopLevelDomainListPsr16Cache($cache, 'pdp_', 86400);
@@ -39,7 +39,7 @@ public function testItReturnsAnInstanceIfTheCorrectCacheExists(): void
3939

4040
public function testItReturnsNullIfTheCacheContentContainsInvalidJsonData(): void
4141
{
42-
$cache = $this->createStub(CacheInterface::class);
42+
$cache = self::createStub(CacheInterface::class);
4343
$cache->method('get')->willReturn('foobar');
4444

4545
$instance = new TopLevelDomainListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));
@@ -49,7 +49,7 @@ public function testItReturnsNullIfTheCacheContentContainsInvalidJsonData(): voi
4949

5050
public function testItReturnsNullIfTheCacheContentCannotBeConvertedToTheCorrectInstance(): void
5151
{
52-
$cache = $this->createStub(CacheInterface::class);
52+
$cache = self::createStub(CacheInterface::class);
5353
$cache->method('get')->willReturn('{"foo":"bar"}');
5454

5555
$instance = new TopLevelDomainListPsr16Cache($cache, 'pdp_', new DateTimeImmutable('+1 DAY'));
@@ -59,7 +59,7 @@ public function testItReturnsNullIfTheCacheContentCannotBeConvertedToTheCorrectI
5959

6060
public function testItCanStoreAPublicSuffixListInstance(): void
6161
{
62-
$cache = $this->createStub(CacheInterface::class);
62+
$cache = self::createStub(CacheInterface::class);
6363
$cache->method('set')->willReturn(true);
6464

6565
$rzd = TopLevelDomains::fromPath(dirname(__DIR__, 2).'/test_data/tlds-alpha-by-domain.txt');
@@ -70,7 +70,7 @@ public function testItCanStoreAPublicSuffixListInstance(): void
7070

7171
public function testItReturnsFalseIfItCantStoreAPublicSuffixListInstance(): void
7272
{
73-
$cache = $this->createStub(CacheInterface::class);
73+
$cache = self::createStub(CacheInterface::class);
7474
$cache->method('set')->willReturn(false);
7575

7676
$rzd = TopLevelDomains::fromPath(dirname(__DIR__, 2).'/test_data/tlds-alpha-by-domain.txt');
@@ -83,7 +83,7 @@ public function testItReturnsFalseIfItCantCacheATopLevelDomainListInstance(): vo
8383
{
8484
$exception = new class('Something went wrong.', 0) extends RuntimeException implements CacheException {
8585
};
86-
$cache = $this->createStub(CacheInterface::class);
86+
$cache = self::createStub(CacheInterface::class);
8787
$cache->method('set')->will(self::throwException($exception));
8888

8989
$rzd = TopLevelDomains::fromPath(dirname(__DIR__, 2).'/test_data/tlds-alpha-by-domain.txt');
@@ -96,7 +96,7 @@ public function testItThrowsIfItCantCacheATopLevelDomainListInstance(): void
9696
{
9797
$exception = new class('Something went wrong.', 0) extends RuntimeException {
9898
};
99-
$cache = $this->createStub(CacheInterface::class);
99+
$cache = self::createStub(CacheInterface::class);
100100
$cache->method('set')->will(self::throwException($exception));
101101

102102
$rzd = TopLevelDomains::fromPath(dirname(__DIR__, 2).'/test_data/tlds-alpha-by-domain.txt');
@@ -111,7 +111,7 @@ public function testItCanDeleteTheCachedDatabase(): void
111111
{
112112
$uri = 'http://www.example.com';
113113

114-
$cache = $this->createStub(CacheInterface::class);
114+
$cache = self::createStub(CacheInterface::class);
115115
$cache->method('delete')->willReturn(true);
116116

117117
$instance = new TopLevelDomainListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));
@@ -122,7 +122,7 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
122122
{
123123
$this->expectException(InvalidArgumentException::class);
124124

125-
$cache = $this->createStub(CacheInterface::class);
125+
$cache = self::createStub(CacheInterface::class);
126126
new TopLevelDomainListPsr16Cache($cache, 'pdp_', 'foobar');
127127
}
128128
}

0 commit comments

Comments
 (0)