From a422df54fae41bcc90b5dfb234362c7cf6cc2cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 4 Dec 2024 14:34:20 +0100 Subject: [PATCH] Upgrade PHPUnit --- composer.json | 3 ++- phpstan.neon.dist | 5 ++++ phpunit.xml.dist | 31 ++++++++++++++----------- tests/mutex/PgAdvisoryLockMutexTest.php | 29 +++++++++++++++-------- tests/mutex/PredisMutexTest.php | 3 ++- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 76481988..df295e55 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "ext-sysvsem": "*", "eloquent/liberator": "^2.0 || ^3.0", "ergebnis/composer-normalize": "^2.13", + "ergebnis/phpunit-slow-test-detector": "^2.9", "friendsofphp/php-cs-fixer": "^3.0", "mikey179/vfsstream": "^1.6.11", "php-mock/php-mock-phpunit": "^2.1", @@ -53,7 +54,7 @@ "phpstan/phpstan": "^2.0", "phpstan/phpstan-deprecation-rules": "^2.0", "phpstan/phpstan-strict-rules": "^2.0", - "phpunit/phpunit": "^9.4", + "phpunit/phpunit": "^9.5.25 || ^10.0 || ^11.0", "predis/predis": "^1.1.8", "spatie/async": "^1.5" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a5dd35d8..305b100f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -31,3 +31,8 @@ parameters: identifier: empty.notAllowed message: '~^Construct empty\(\) is not allowed\. Use more strict comparison\.$~' count: 6 + - + path: '*' + identifier: method.deprecated + message: '~^Call to deprecated method getMockForAbstractClass\(\) of class PHPUnit\\Framework\\TestCase:\nhttps://github.com/sebastianbergmann/phpunit/issues/5241$~' + count: 8 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 96cd01b1..6f14faf0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,21 @@ - - + - - ./tests + + tests + + + + + + src + tests + + + + + + + diff --git a/tests/mutex/PgAdvisoryLockMutexTest.php b/tests/mutex/PgAdvisoryLockMutexTest.php index 83abffe0..44a2d461 100644 --- a/tests/mutex/PgAdvisoryLockMutexTest.php +++ b/tests/mutex/PgAdvisoryLockMutexTest.php @@ -24,6 +24,11 @@ protected function setUp(): void $this->mutex = new PgAdvisoryLockMutex($this->pdo, 'test' . uniqid()); } + private function isPhpunit9x(): bool + { + return (new \ReflectionClass(self::class))->hasMethod('getStatus'); + } + public function testAcquireLock(): void { $statement = $this->createMock(\PDOStatement::class); @@ -39,11 +44,13 @@ public function testAcquireLock(): void self::logicalAnd( self::isType('array'), self::countOf(2), - self::callback(static function (...$arguments): bool { - $integers = $arguments[0]; + self::callback(function (...$arguments): bool { + if ($this->isPhpunit9x()) { // https://github.com/sebastianbergmann/phpunit/issues/5891 + $arguments = $arguments[0]; + } - foreach ($integers as $each) { - self::assertIsInt($each); + foreach ($arguments as $v) { + self::assertIsInt($v); } return true; @@ -69,13 +76,15 @@ public function testReleaseLock(): void self::logicalAnd( self::isType('array'), self::countOf(2), - self::callback(static function (...$arguments): bool { - $integers = $arguments[0]; + self::callback(function (...$arguments): bool { + if ($this->isPhpunit9x()) { // https://github.com/sebastianbergmann/phpunit/issues/5891 + $arguments = $arguments[0]; + } - foreach ($integers as $each) { - self::assertLessThan(1 << 32, $each); - self::assertGreaterThan(-(1 << 32), $each); - self::assertIsInt($each); + foreach ($arguments as $v) { + self::assertLessThan(1 << 32, $v); + self::assertGreaterThan(-(1 << 32), $v); + self::assertIsInt($v); } return true; diff --git a/tests/mutex/PredisMutexTest.php b/tests/mutex/PredisMutexTest.php index 4a7a3677..f4872fe4 100644 --- a/tests/mutex/PredisMutexTest.php +++ b/tests/mutex/PredisMutexTest.php @@ -31,7 +31,8 @@ protected function setUp(): void parent::setUp(); $this->client = $this->getMockBuilder(ClientInterface::class) // @phpstan-ignore method.deprecated - ->setMethods(array_merge(get_class_methods(ClientInterface::class), ['set', 'eval'])) + ->onlyMethods(get_class_methods(ClientInterface::class)) + ->addMethods(['set', 'eval']) ->getMock(); $this->mutex = new PredisMutex([$this->client], 'test', 2.5);