From 62d5982513407375841fa85d099aae7846f125f9 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Wed, 14 Aug 2024 15:01:26 -0400 Subject: [PATCH] Upgraded to Phpunit 11 for PHP >=8.2 Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- composer.json | 2 +- phpunit.xml.dist | 19 +++++++++---------- tests/Factory/CorsOptionsFactoryTest.php | 3 ++- .../CorsRequestListenerFactoryTest.php | 3 ++- tests/Factory/CorsServiceFactoryTest.php | 3 ++- tests/ModuleTest.php | 16 ++++++---------- tests/Mvc/CorsRequestListenerTest.php | 10 ++++++---- tests/Options/CorsOptionsTest.php | 3 ++- tests/Service/CorsServiceTest.php | 3 ++- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index e2717c7..4d42ede 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "laminas/laminas-modulemanager": "^2.7.2", "laminas/laminas-serializer": "^2.8", "laminas/laminas-view": "^2.8.1", - "phpunit/phpunit": "^9.5.0", + "phpunit/phpunit": "^10.5 || ^11.0", "php-coveralls/php-coveralls": "^2.1", "squizlabs/php_codesniffer": "^3.4" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8ad41e7..7e70aaa 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,15 @@ - - - ./src - - + bootstrap="./tests/Bootstrap.php" + colors="true" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache"> ./tests + + + ./src + + diff --git a/tests/Factory/CorsOptionsFactoryTest.php b/tests/Factory/CorsOptionsFactoryTest.php index 3f0e961..e332e45 100644 --- a/tests/Factory/CorsOptionsFactoryTest.php +++ b/tests/Factory/CorsOptionsFactoryTest.php @@ -19,6 +19,7 @@ namespace LmcCorsTest\Factory; use LmcCors\Options\CorsOptions; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use LmcCorsTest\Util\ServiceManagerFactory; use Psr\Container\ContainerExceptionInterface; @@ -29,9 +30,9 @@ * * @author Michaël Gallego * - * @covers \LmcCors\Factory\CorsOptionsFactory * @group Coverage */ +#[CoversClass('\LmcCors\Factory\CorsOptionsFactory')] class CorsOptionsFactoryTest extends TestCase { /** diff --git a/tests/Factory/CorsRequestListenerFactoryTest.php b/tests/Factory/CorsRequestListenerFactoryTest.php index 9439a6d..158e727 100644 --- a/tests/Factory/CorsRequestListenerFactoryTest.php +++ b/tests/Factory/CorsRequestListenerFactoryTest.php @@ -19,6 +19,7 @@ namespace LmcCorsTest\Factory; use LmcCors\Mvc\CorsRequestListener; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use LmcCorsTest\Util\ServiceManagerFactory; @@ -27,9 +28,9 @@ * * @author Michaël Gallego * - * @covers \LmcCors\Factory\CorsRequestListenerFactory * @group Coverage */ +#[CoversClass('\LmcCors\Factory\CorsRequestListenerFactory')] class CorsRequestListenerFactoryTest extends TestCase { public function testCanCreateCorsRequestListener() diff --git a/tests/Factory/CorsServiceFactoryTest.php b/tests/Factory/CorsServiceFactoryTest.php index c2a9223..8117aec 100644 --- a/tests/Factory/CorsServiceFactoryTest.php +++ b/tests/Factory/CorsServiceFactoryTest.php @@ -19,6 +19,7 @@ namespace LmcCorsTest\Factory; use LmcCors\Service\CorsService; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase as TestCase; use LmcCorsTest\Util\ServiceManagerFactory; @@ -27,9 +28,9 @@ * * @author Michaël Gallego * - * @covers \LmcCors\Factory\CorsServiceFactory * @group Coverage */ +#[CoversClass('\LmcCors\Factory\CorsServiceFactory')] class CorsServiceFactoryTest extends TestCase { public function testCanCreateCorsService() diff --git a/tests/ModuleTest.php b/tests/ModuleTest.php index 98d9a2e..707fae0 100644 --- a/tests/ModuleTest.php +++ b/tests/ModuleTest.php @@ -18,6 +18,7 @@ namespace LmcCorsTest; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use LmcCors\Module; @@ -29,11 +30,9 @@ * * @group Coverage */ +#[CoversClass('\LmcCors\Module')] class ModuleTest extends TestCase { - /** - * @covers \LmcCors\Module::getConfig - */ public function testGetConfig() { $module = new Module(); @@ -42,9 +41,6 @@ public function testGetConfig() $this->assertSame($module->getConfig(), unserialize(serialize($module->getConfig())), 'Config is serializable'); } - /** - * @covers \LmcCors\Module::onBootstrap - */ public function testAssertListenerIsCorrectlyRegistered() { $module = new Module(); @@ -58,14 +54,14 @@ public function testAssertListenerIsCorrectlyRegistered() ->disableOriginalConstructor() ->getMock(); - $mvcEvent->expects($this->any())->method('getTarget')->will($this->returnValue($application)); - $application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); - $application->expects($this->any())->method('getServiceManager')->will($this->returnValue($serviceManager)); + $mvcEvent->expects($this->any())->method('getTarget')->willReturn($application); + $application->expects($this->any())->method('getEventManager')->willReturn($eventManager); + $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); $serviceManager ->expects($this->any()) ->method('get') ->with('LmcCors\Mvc\CorsRequestListener') - ->will($this->returnValue($corsListener)); + ->willReturn($corsListener); $corsListener->expects($this->once())->method('attach')->with($eventManager); diff --git a/tests/Mvc/CorsRequestListenerTest.php b/tests/Mvc/CorsRequestListenerTest.php index 27e375b..afa0073 100644 --- a/tests/Mvc/CorsRequestListenerTest.php +++ b/tests/Mvc/CorsRequestListenerTest.php @@ -18,6 +18,7 @@ namespace LmcCorsTest\Mvc; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Laminas\EventManager\EventManager; use Laminas\Http\Request as HttpRequest; @@ -34,9 +35,9 @@ * * @author Michaël Gallego * - * @covers \LmcCors\Mvc\CorsRequestListener * @group Coverage */ +#[CoversClass('\LmcCors\Mvc\CorsRequestListener')] class CorsRequestListenerTest extends TestCase { @@ -67,13 +68,14 @@ public function testAttach() $eventManager = $this->getMockBuilder('Laminas\EventManager\EventManagerInterface')->getMock(); $matcher = $this->exactly(2); + $eventManager ->expects($matcher) ->method('attach') ->willReturnCallback(function (string $event, callable $callback, int $priority) use ($matcher) { - match ($matcher->getInvocationCount()) { - 1 => $this->assertEquals(MvcEvent::EVENT_ROUTE, $event), - 2 => $this->assertEquals(MvcEvent::EVENT_FINISH, $event), + match ($event) { + MvcEvent::EVENT_ROUTE => '', + MvcEvent::EVENT_FINISH => '', }; }); $this->corsListener->attach($eventManager); diff --git a/tests/Options/CorsOptionsTest.php b/tests/Options/CorsOptionsTest.php index 9b7f642..83fc2a5 100644 --- a/tests/Options/CorsOptionsTest.php +++ b/tests/Options/CorsOptionsTest.php @@ -18,6 +18,7 @@ namespace LmcCorsTest\Options; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use LmcCors\Options\CorsOptions; @@ -26,9 +27,9 @@ * * @author Michaël Gallego * - * @covers \LmcCors\Options\CorsOptions * @group Coverage */ +#[CoversClass('\LmcCors\Options\CorsOptions')] class CorsOptionsTest extends TestCase { public function testCorsOptionsAreSecuredByDefault() diff --git a/tests/Service/CorsServiceTest.php b/tests/Service/CorsServiceTest.php index a8deb31..7b52f23 100644 --- a/tests/Service/CorsServiceTest.php +++ b/tests/Service/CorsServiceTest.php @@ -20,6 +20,7 @@ use LmcCors\Exception\DisallowedOriginException; use LmcCors\Exception\InvalidOriginException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Laminas\Http\Response as HttpResponse; use Laminas\Http\Request as HttpRequest; @@ -33,9 +34,9 @@ * * @author Florent Blaison * - * @covers \LmcCors\Service\CorsService * @group Coverage */ +#[CoversClass('\LmcCors\Service\CorsService')] class CorsServiceTest extends TestCase { /**