Skip to content

Commit

Permalink
Indicate data providers as annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
IngeniozIT committed Apr 2, 2024
1 parent 13b9940 commit 5fd2b98
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 3 additions & 6 deletions tests/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
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;
use Psr\Http\Server\RequestHandlerInterface;

final class CallbackTest extends RouterCase
{
/**
* @dataProvider providerCallbacks
*/
#[DataProvider('providerCallbacks')]
public function testRouterCanExecuteACallback(Closure|MiddlewareInterface|RequestHandlerInterface|string $callback): void
{
$routeGroup = new RouteGroup(routes: [
Expand Down Expand Up @@ -55,9 +54,7 @@ public static function providerCallbacks(): array
];
}

/**
* @dataProvider providerInvalidHandlers
*/
#[DataProvider('providerInvalidHandlers')]
public function testRouterCannotExecuteAnInvalidCallback(mixed $callback): void
{
$routeGroup = new RouteGroup(routes: [
Expand Down
9 changes: 3 additions & 6 deletions tests/ConditionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions tests/HttpMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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'));
Expand Down
9 changes: 3 additions & 6 deletions tests/MiddlewaresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,9 +18,7 @@

final class MiddlewaresTest extends RouterCase
{
/**
* @dataProvider providerMiddlewares
*/
#[DataProvider('providerMiddlewares')]
public function testRouteGroupsCanHaveMiddlewares(mixed $middleware, string $expectedResponse): void
{
$routeGroup = new RouteGroup(
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions tests/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 5fd2b98

Please sign in to comment.