Skip to content

Commit

Permalink
Add support for PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Apr 13, 2024
1 parent bf4783d commit c4c8528
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.52.1",
"friendsofphp/php-cs-fixer": "^3.53.0",
"guzzlehttp/guzzle": "^7.8.1",
"guzzlehttp/psr7": "^1.6 || ^2.6.2",
"phpstan/phpstan": "^1.10.64",
"phpstan/phpstan": "^1.10.66",
"phpstan/phpstan-phpunit": "^1.3.16",
"phpstan/phpstan-strict-rules": "^1.5.2",
"phpunit/phpunit": "^10.5.15",
"phpstan/phpstan-strict-rules": "^1.5.3",
"phpunit/phpunit": "^10.5.15 || ^11.1.1",
"psr/http-factory": "^1.0.2",
"psr/simple-cache": "^1.0.1",
"symfony/cache": "^v5.0.0 || ^6.4.4"
"symfony/cache": "^v5.0.0 || ^6.4.6"
},
"suggest": {
"psr/http-client-implementation": "To use the storage functionnality which depends on PSR-18",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ parameters:
path: src/Rules.php
- message: '#Variable \$line on left side of \?\? always exists and is not nullable.#'
path: src/Rules.php
- '#^Parameter \#1 \$callback of function set_error_handler expects#'
reportUnmatchedIgnoredErrors: true
4 changes: 2 additions & 2 deletions src/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ public static function toUnicodeProvider(): iterable
public function testToAscii(
?string $domain,
?string $expectedDomain,
?string $expectedAsciiDomain
?string $expectedIDNDomain
): void {
$domain = Domain::fromIDNA2008($domain);
self::assertSame($expectedDomain, $domain->value());

/** @var Domain $domainIDN */
$domainIDN = $domain->toAscii();
self::assertSame($expectedAsciiDomain, $domainIDN->value());
self::assertSame($expectedIDNDomain, $domainIDN->value());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/ResolvedDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ public function testItCanBeConvertedToAscii(
?string $publicSuffix,
?string $expectedDomain,
?string $expectedSuffix,
?string $expectedAsciiDomain,
?string $expectedAsciiSuffix
?string $expectedIDNDomain,
?string $expectedIDNSuffix
): void {
$domain = ResolvedDomain::fromUnknown(Domain::fromIDNA2003($domain), count(Domain::fromIDNA2003($publicSuffix)));
self::assertSame($expectedDomain, $domain->value());
self::assertSame($expectedSuffix, $domain->suffix()->value());

/** @var ResolvedDomain $domainIDN */
$domainIDN = $domain->toAscii();
self::assertSame($expectedAsciiDomain, $domainIDN->value());
self::assertSame($expectedAsciiSuffix, $domainIDN->suffix()->value());
self::assertSame($expectedIDNDomain, $domainIDN->value());
self::assertSame($expectedIDNSuffix, $domainIDN->suffix()->value());
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/Storage/PublicSuffixListPsr16CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use InvalidArgumentException;
use Pdp\Rules;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\ErrorHandler;
use Psr\SimpleCache\CacheException;
use Psr\SimpleCache\CacheInterface;
use RuntimeException;
Expand Down Expand Up @@ -128,4 +129,38 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
$cache = self::createStub(CacheInterface::class);
new PublicSuffixListPsr16Cache($cache, 'pdp_', 'foobar');
}

protected function restoreExceptionHandler(): void
{
while (true) {
$previousHandler = set_exception_handler(static fn () => null);
restore_exception_handler();
if (null === $previousHandler) {
break;
}

restore_exception_handler();
}
}

protected function restoreErrorHandler(): void
{
while (true) {
$previousHandler = set_error_handler(static fn (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) => null);
restore_error_handler();
$isPhpUnitErrorHandler = ($previousHandler instanceof ErrorHandler);
if (null === $previousHandler || $isPhpUnitErrorHandler) {
break;
}
restore_error_handler();
}
}

protected function tearDown(): void
{
parent::tearDown();

$this->restoreErrorHandler();
$this->restoreExceptionHandler();
}
}
4 changes: 1 addition & 3 deletions src/Storage/TimeToLiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public function testItDoesNotReturnTheAbsoluteInterval(): void
self::assertSame(0, TimeToLive::until($tomorrow)->invert);
}

/**
* @dataProvider validDurationString
*/
#[DataProvider('validDurationString')]
public function testItCanBeInstantiatedFromDurationInput(string $input, DateInterval $expected): void
{
$now = new DateTimeImmutable();
Expand Down
37 changes: 37 additions & 0 deletions src/Storage/TopLevelDomainListPsr16CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use InvalidArgumentException;
use Pdp\TopLevelDomains;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\ErrorHandler;
use Psr\SimpleCache\CacheException;
use Psr\SimpleCache\CacheInterface;
use RuntimeException;
Expand Down Expand Up @@ -125,4 +126,40 @@ public function testItWillThrowIfTheTTLIsNotParsable(): void
$cache = self::createStub(CacheInterface::class);
new TopLevelDomainListPsr16Cache($cache, 'pdp_', 'foobar');
}



protected function restoreExceptionHandler(): void
{
while (true) {
$previousHandler = set_exception_handler(static fn () => null);
restore_exception_handler();
if (null === $previousHandler) {
break;
}

restore_exception_handler();
}
}

protected function restoreErrorHandler(): void
{
while (true) {
$previousHandler = set_error_handler(static fn (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) => null);
restore_error_handler();
$isPhpUnitErrorHandler = ($previousHandler instanceof ErrorHandler);
if (null === $previousHandler || $isPhpUnitErrorHandler) {
break;
}
restore_error_handler();
}
}

protected function tearDown(): void
{
parent::tearDown();

$this->restoreErrorHandler();
$this->restoreExceptionHandler();
}
}

0 comments on commit c4c8528

Please sign in to comment.