Skip to content

Commit c4c8528

Browse files
committed
Add support for PHPUnit 11
1 parent bf4783d commit c4c8528

File tree

7 files changed

+85
-14
lines changed

7 files changed

+85
-14
lines changed

composer.json

Lines changed: 5 additions & 5 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": "^3.52.1",
49+
"friendsofphp/php-cs-fixer": "^3.53.0",
5050
"guzzlehttp/guzzle": "^7.8.1",
5151
"guzzlehttp/psr7": "^1.6 || ^2.6.2",
52-
"phpstan/phpstan": "^1.10.64",
52+
"phpstan/phpstan": "^1.10.66",
5353
"phpstan/phpstan-phpunit": "^1.3.16",
54-
"phpstan/phpstan-strict-rules": "^1.5.2",
55-
"phpunit/phpunit": "^10.5.15",
54+
"phpstan/phpstan-strict-rules": "^1.5.3",
55+
"phpunit/phpunit": "^10.5.15 || ^11.1.1",
5656
"psr/http-factory": "^1.0.2",
5757
"psr/simple-cache": "^1.0.1",
58-
"symfony/cache": "^v5.0.0 || ^6.4.4"
58+
"symfony/cache": "^v5.0.0 || ^6.4.6"
5959
},
6060
"suggest": {
6161
"psr/http-client-implementation": "To use the storage functionnality which depends on PSR-18",

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ parameters:
1212
path: src/Rules.php
1313
- message: '#Variable \$line on left side of \?\? always exists and is not nullable.#'
1414
path: src/Rules.php
15+
- '#^Parameter \#1 \$callback of function set_error_handler expects#'
1516
reportUnmatchedIgnoredErrors: true

src/DomainTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ public static function toUnicodeProvider(): iterable
168168
public function testToAscii(
169169
?string $domain,
170170
?string $expectedDomain,
171-
?string $expectedAsciiDomain
171+
?string $expectedIDNDomain
172172
): void {
173173
$domain = Domain::fromIDNA2008($domain);
174174
self::assertSame($expectedDomain, $domain->value());
175175

176176
/** @var Domain $domainIDN */
177177
$domainIDN = $domain->toAscii();
178-
self::assertSame($expectedAsciiDomain, $domainIDN->value());
178+
self::assertSame($expectedIDNDomain, $domainIDN->value());
179179
}
180180

181181
/**

src/ResolvedDomainTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ public function testItCanBeConvertedToAscii(
173173
?string $publicSuffix,
174174
?string $expectedDomain,
175175
?string $expectedSuffix,
176-
?string $expectedAsciiDomain,
177-
?string $expectedAsciiSuffix
176+
?string $expectedIDNDomain,
177+
?string $expectedIDNSuffix
178178
): void {
179179
$domain = ResolvedDomain::fromUnknown(Domain::fromIDNA2003($domain), count(Domain::fromIDNA2003($publicSuffix)));
180180
self::assertSame($expectedDomain, $domain->value());
181181
self::assertSame($expectedSuffix, $domain->suffix()->value());
182182

183183
/** @var ResolvedDomain $domainIDN */
184184
$domainIDN = $domain->toAscii();
185-
self::assertSame($expectedAsciiDomain, $domainIDN->value());
186-
self::assertSame($expectedAsciiSuffix, $domainIDN->suffix()->value());
185+
self::assertSame($expectedIDNDomain, $domainIDN->value());
186+
self::assertSame($expectedIDNSuffix, $domainIDN->suffix()->value());
187187
}
188188

189189
/**

src/Storage/PublicSuffixListPsr16CacheTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use InvalidArgumentException;
1010
use Pdp\Rules;
1111
use PHPUnit\Framework\TestCase;
12+
use PHPUnit\Runner\ErrorHandler;
1213
use Psr\SimpleCache\CacheException;
1314
use Psr\SimpleCache\CacheInterface;
1415
use RuntimeException;
@@ -128,4 +129,38 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
128129
$cache = self::createStub(CacheInterface::class);
129130
new PublicSuffixListPsr16Cache($cache, 'pdp_', 'foobar');
130131
}
132+
133+
protected function restoreExceptionHandler(): void
134+
{
135+
while (true) {
136+
$previousHandler = set_exception_handler(static fn () => null);
137+
restore_exception_handler();
138+
if (null === $previousHandler) {
139+
break;
140+
}
141+
142+
restore_exception_handler();
143+
}
144+
}
145+
146+
protected function restoreErrorHandler(): void
147+
{
148+
while (true) {
149+
$previousHandler = set_error_handler(static fn (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) => null);
150+
restore_error_handler();
151+
$isPhpUnitErrorHandler = ($previousHandler instanceof ErrorHandler);
152+
if (null === $previousHandler || $isPhpUnitErrorHandler) {
153+
break;
154+
}
155+
restore_error_handler();
156+
}
157+
}
158+
159+
protected function tearDown(): void
160+
{
161+
parent::tearDown();
162+
163+
$this->restoreErrorHandler();
164+
$this->restoreExceptionHandler();
165+
}
131166
}

src/Storage/TimeToLiveTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public function testItDoesNotReturnTheAbsoluteInterval(): void
2222
self::assertSame(0, TimeToLive::until($tomorrow)->invert);
2323
}
2424

25-
/**
26-
* @dataProvider validDurationString
27-
*/
25+
#[DataProvider('validDurationString')]
2826
public function testItCanBeInstantiatedFromDurationInput(string $input, DateInterval $expected): void
2927
{
3028
$now = new DateTimeImmutable();

src/Storage/TopLevelDomainListPsr16CacheTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use InvalidArgumentException;
1010
use Pdp\TopLevelDomains;
1111
use PHPUnit\Framework\TestCase;
12+
use PHPUnit\Runner\ErrorHandler;
1213
use Psr\SimpleCache\CacheException;
1314
use Psr\SimpleCache\CacheInterface;
1415
use RuntimeException;
@@ -125,4 +126,40 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
125126
$cache = self::createStub(CacheInterface::class);
126127
new TopLevelDomainListPsr16Cache($cache, 'pdp_', 'foobar');
127128
}
129+
130+
131+
132+
protected function restoreExceptionHandler(): void
133+
{
134+
while (true) {
135+
$previousHandler = set_exception_handler(static fn () => null);
136+
restore_exception_handler();
137+
if (null === $previousHandler) {
138+
break;
139+
}
140+
141+
restore_exception_handler();
142+
}
143+
}
144+
145+
protected function restoreErrorHandler(): void
146+
{
147+
while (true) {
148+
$previousHandler = set_error_handler(static fn (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) => null);
149+
restore_error_handler();
150+
$isPhpUnitErrorHandler = ($previousHandler instanceof ErrorHandler);
151+
if (null === $previousHandler || $isPhpUnitErrorHandler) {
152+
break;
153+
}
154+
restore_error_handler();
155+
}
156+
}
157+
158+
protected function tearDown(): void
159+
{
160+
parent::tearDown();
161+
162+
$this->restoreErrorHandler();
163+
$this->restoreExceptionHandler();
164+
}
128165
}

0 commit comments

Comments
 (0)