From 5fd2b9839f086c7f9125fb18fda883960d7a2e4a Mon Sep 17 00:00:00 2001 From: IngeniozIT Date: Tue, 2 Apr 2024 21:06:34 +0200 Subject: [PATCH] Indicate data providers as annotations --- composer.json | 4 ++-- tests/CallbackTest.php | 9 +++------ tests/ConditionsTest.php | 9 +++------ tests/HttpMethodTest.php | 9 +++------ tests/MiddlewaresTest.php | 9 +++------ tests/RoutingTest.php | 5 ++--- 6 files changed, 16 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index e0ecace..7d91f4f 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "infection/infection": "*", "phpmd/phpmd": "*", "rector/rector": "*", - "ingenioz-it/http-message": "^2.0", - "ingenioz-it/edict": "^3.1" + "ingenioz-it/http-message": "*", + "ingenioz-it/edict": "*" }, "autoload": { "psr-4": { diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 4389a8b..051497e 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -10,6 +10,7 @@ use IngeniozIT\Router\Tests\Utils\RouterCase; use IngeniozIT\Router\Tests\Utils\TestHandler; use IngeniozIT\Router\Tests\Utils\TestMiddleware; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -17,9 +18,7 @@ final class CallbackTest extends RouterCase { - /** - * @dataProvider providerCallbacks - */ + #[DataProvider('providerCallbacks')] public function testRouterCanExecuteACallback(Closure|MiddlewareInterface|RequestHandlerInterface|string $callback): void { $routeGroup = new RouteGroup(routes: [ @@ -55,9 +54,7 @@ public static function providerCallbacks(): array ]; } - /** - * @dataProvider providerInvalidHandlers - */ + #[DataProvider('providerInvalidHandlers')] public function testRouterCannotExecuteAnInvalidCallback(mixed $callback): void { $routeGroup = new RouteGroup(routes: [ diff --git a/tests/ConditionsTest.php b/tests/ConditionsTest.php index ecee26f..e06ef07 100644 --- a/tests/ConditionsTest.php +++ b/tests/ConditionsTest.php @@ -8,14 +8,13 @@ use IngeniozIT\Router\Route; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; final class ConditionsTest extends RouterCase { - /** - * @dataProvider providerConditions - */ + #[DataProvider('providerConditions')] public function testRouteGroupsCanHaveConditions(Closure $condition, string $expectedResponse): void { $routeGroup = new RouteGroup( @@ -88,9 +87,7 @@ public function testConditionsCanAddAttributesToARequest(): void self::assertEquals("'bar'", (string)$response->getBody()); } - /** - * @dataProvider providerInvalidConditions - */ + #[DataProvider('providerInvalidConditions')] public function testRouterCannotExecuteInvalidConditions(mixed $condition): void { $routeGroup = new RouteGroup( diff --git a/tests/HttpMethodTest.php b/tests/HttpMethodTest.php index 5d31d61..8abe832 100644 --- a/tests/HttpMethodTest.php +++ b/tests/HttpMethodTest.php @@ -6,13 +6,12 @@ use IngeniozIT\Router\RouteElement; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\ResponseInterface; final class HttpMethodTest extends RouterCase { - /** - * @dataProvider providerMethodsAndRoutes - */ + #[DataProvider('providerMethodsAndRoutes')] public function testRoutesMatchRequestsBasedOnMethod(string $method, callable $routeCallable): void { /** @var RouteElement $route */ @@ -40,9 +39,7 @@ public static function providerMethodsAndRoutes(): array ]; } - /** - * @dataProvider providerRouteMethods - */ + #[DataProvider('providerRouteMethods')] public function testRoutesCanMatchAnyMethod(string $method): void { $route = Route::any('/', static fn(): ResponseInterface => self::response('OK')); diff --git a/tests/MiddlewaresTest.php b/tests/MiddlewaresTest.php index 2bb8bc1..663ae05 100644 --- a/tests/MiddlewaresTest.php +++ b/tests/MiddlewaresTest.php @@ -9,6 +9,7 @@ use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; use IngeniozIT\Router\Tests\Utils\TestMiddleware; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -17,9 +18,7 @@ final class MiddlewaresTest extends RouterCase { - /** - * @dataProvider providerMiddlewares - */ + #[DataProvider('providerMiddlewares')] public function testRouteGroupsCanHaveMiddlewares(mixed $middleware, string $expectedResponse): void { $routeGroup = new RouteGroup( @@ -71,9 +70,7 @@ public function testRouteGroupsCanHaveMultipleMiddlewares(): void self::assertEquals('TEST', (string) $response->getBody()); } - /** - * @dataProvider providerInvalidMiddlewares - */ + #[DataProvider('providerInvalidMiddlewares')] public function testRouterCannotExecuteInvalidMiddlewares(mixed $middleware): void { $routeGroup = new RouteGroup( diff --git a/tests/RoutingTest.php b/tests/RoutingTest.php index 57ca366..95c91ec 100644 --- a/tests/RoutingTest.php +++ b/tests/RoutingTest.php @@ -6,6 +6,7 @@ use IngeniozIT\Router\Route; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -101,9 +102,7 @@ public function testRoutesCanUsePathParameters(): void self::assertEquals('barbaz', (string)$response->getBody()); } - /** - * @dataProvider providerRouteGroupsWithCustomParameters - */ + #[DataProvider('providerRouteGroupsWithCustomParameters')] public function testRoutesCanUseCustomPathParameters(RouteGroup $routeGroup): void { $matchingRequest = self::serverRequest('GET', '/123');