diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fb4f68..5622069 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,41 +3,40 @@ name: CI on: [push, pull_request] jobs: - build-test: - runs-on: ubuntu-latest - strategy: - matrix: - php_version: [8.0, 8.1, 8.2] - composer_flags: ['', '--prefer-lowest'] - - steps: - - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php_version }} - extensions: xdebug - - - uses: php-actions/composer@v5 - with: - php_version: ${{ matrix.php_version }} - args: ${{ matrix.composer_flags }} - command: update - - - name: Run tests - run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml - env: - XDEBUG_MODE: coverage - - # - name: Submit coverage to Coveralls - # # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports: - # # https://github.com/coverallsapp/github-action/issues/15 - # env: - # COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # COVERALLS_PARALLEL: true - # COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }} - # run: | - # composer global require php-coveralls/php-coveralls - # ~/.composer/vendor/bin/php-coveralls -v - + build-test: + runs-on: ubuntu-latest + strategy: + matrix: + php_version: [8.1, 8.2, 8.3, 8.4] + composer_flags: ["", "--prefer-lowest"] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + extensions: xdebug + + - uses: php-actions/composer@v5 + with: + php_version: ${{ matrix.php_version }} + args: ${{ matrix.composer_flags }} + command: update + + - name: Run tests + run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml + env: + XDEBUG_MODE: coverage + + # - name: Submit coverage to Coveralls + # # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports: + # # https://github.com/coverallsapp/github-action/issues/15 + # env: + # COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # COVERALLS_PARALLEL: true + # COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }} + # run: | + # composer global require php-coveralls/php-coveralls + # ~/.composer/vendor/bin/php-coveralls -v diff --git a/composer.json b/composer.json index 058ee55..5ff217b 100755 --- a/composer.json +++ b/composer.json @@ -16,21 +16,21 @@ } ], "require": { - "php": "^7.3||^8.0", - "altorouter/altorouter": "^2.0.2", - "mindplay/middleman": "^3.0.3", - "php-di/invoker": "^2.3.0", - "psr/container": "^1.0", - "psr/http-message": "^1.0", + "php": ">=8.1", + "altorouter/altorouter": "^2.0.3", + "laminas/laminas-diactoros": "^3.6.0", + "mindplay/middleman": "^4.0.4", + "php-di/invoker": "^2.3.6", + "psr/container": "^2.0.2", + "psr/http-message": "^2.0", "psr/http-server-middleware": "^1.0", - "spatie/macroable": "^1.0", - "laminas/laminas-diactoros": "^2.4" + "spatie/macroable": "^1.0" }, "require-dev": { - "php-di/php-di": "^6.3.4", - "phpunit/phpunit": "^9.5", - "php-coveralls/php-coveralls": "^2.4", "mockery/mockery": "^1.4.3", + "php-coveralls/php-coveralls": "^2.4", + "php-di/php-di": "^7.1.1", + "phpunit/phpunit": "^10.5", "squizlabs/php_codesniffer": "^3.6.0" }, "autoload": { @@ -49,4 +49,4 @@ "config": { "sort-packages": true } -} +} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 62992c9..18d4d24 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,13 @@ - - - - tests - - - - - src/ - - + + + + tests + + + + + src/ + + diff --git a/src/Route.php b/src/Route.php index 9f74723..d6f3a30 100644 --- a/src/Route.php +++ b/src/Route.php @@ -35,8 +35,8 @@ public function __construct( array $methods, string $uri, $action, - Invoker $invoker = null, - MiddlewareResolver $resolver = null + ?Invoker $invoker = null, + ?MiddlewareResolver $resolver = null ) { $this->invoker = $invoker; $this->middlewareResolver = $resolver; @@ -77,7 +77,7 @@ public function handle(ServerRequest $request, RouteParams $params): ResponseInt return $this->middlewareResolver->resolve($name); }); - return $dispatcher->dispatch($request); + return $dispatcher->handle($request); } private function gatherMiddleware(): array diff --git a/src/RouteAction.php b/src/RouteAction.php index 5bdb7eb..cfcb9ca 100644 --- a/src/RouteAction.php +++ b/src/RouteAction.php @@ -29,7 +29,7 @@ class RouteAction * @param mixed $action * @param Rareloop/Router/Invoker $invoker */ - public function __construct($action, Invoker $invoker = null) + public function __construct($action, ?Invoker $invoker = null) { $this->invoker = $invoker; $this->callable = $this->createCallableFromAction($action); @@ -65,7 +65,7 @@ public function invoke(ServerRequestInterface $request, RouteParams $params) * @param mixed $action * @return callable */ - private function createCallableFromAction($action) : callable + private function createCallableFromAction($action): callable { // Check if this looks like it could be a class/method string if (!is_callable($action) && is_string($action)) { @@ -80,7 +80,7 @@ private function createCallableFromAction($action) : callable * * @return boolean */ - private function isControllerAction() : bool + private function isControllerAction(): bool { return !empty($this->controllerName) && !empty($this->controllerMethod); } @@ -127,7 +127,7 @@ private function createControllerFromClassName($className) * * @return bool */ - private function providesMiddleware() : bool + private function providesMiddleware(): bool { $controller = $this->getController(); @@ -143,7 +143,7 @@ private function providesMiddleware() : bool * * @return array */ - public function getMiddleware() : array + public function getMiddleware(): array { if (!$this->providesMiddleware()) { return []; @@ -170,7 +170,7 @@ function ($controllerMiddleware) { * @param string $string e.g. `MyController@myMethod` * @return Closure */ - private function convertClassStringToFactory($string) : Closure + private function convertClassStringToFactory($string): Closure { $this->controllerName = null; $this->controllerMethod = null; diff --git a/src/Router.php b/src/Router.php index 11d8374..e38d1af 100644 --- a/src/Router.php +++ b/src/Router.php @@ -36,7 +36,7 @@ class Router implements Routable private $invoker = null; private $baseMiddleware = []; - public function __construct(ContainerInterface $container = null, MiddlewareResolver $resolver = null) + public function __construct(?ContainerInterface $container = null, ?MiddlewareResolver $resolver = null) { if (isset($container)) { $this->setContainer($container); @@ -194,7 +194,7 @@ function ($request) use ($route, $params) { return $this->middlewareResolver->resolve($name); }); - return $dispatcher->dispatch($request); + return $dispatcher->handle($request); } public function has(string $name) diff --git a/tests/ControllerMiddlewareOptionsTest.php b/tests/ControllerMiddlewareOptionsTest.php index a5d340b..4df418a 100644 --- a/tests/ControllerMiddlewareOptionsTest.php +++ b/tests/ControllerMiddlewareOptionsTest.php @@ -4,10 +4,11 @@ use PHPUnit\Framework\TestCase; use Rareloop\Router\ControllerMiddlewareOptions; +use PHPUnit\Framework\Attributes\Test; class ControllerMiddlewareOptionsTest extends TestCase { - /** @test */ + #[Test] public function by_default_no_methods_are_excluded() { $options = new ControllerMiddlewareOptions; @@ -16,7 +17,7 @@ public function by_default_no_methods_are_excluded() $this->assertFalse($options->excludedForMethod('bar')); } - /** @test */ + #[Test] public function only_is_chainable() { $options = new ControllerMiddlewareOptions; @@ -24,7 +25,7 @@ public function only_is_chainable() $this->assertSame($options, $options->only('foo')); } - /** @test */ + #[Test] public function can_use_only_to_limit_methods() { $options = new ControllerMiddlewareOptions; @@ -35,7 +36,7 @@ public function can_use_only_to_limit_methods() $this->assertTrue($options->excludedForMethod('bar')); } - /** @test */ + #[Test] public function can_use_only_to_limit_multiple_methods() { $options = new ControllerMiddlewareOptions; @@ -47,7 +48,7 @@ public function can_use_only_to_limit_multiple_methods() $this->assertTrue($options->excludedForMethod('baz')); } - /** @test */ + #[Test] public function except_is_chainable() { $options = new ControllerMiddlewareOptions; @@ -55,7 +56,7 @@ public function except_is_chainable() $this->assertSame($options, $options->except('foo')); } - /** @test */ + #[Test] public function can_use_except_to_limit_methods() { $options = new ControllerMiddlewareOptions; @@ -66,7 +67,7 @@ public function can_use_except_to_limit_methods() $this->assertFalse($options->excludedForMethod('bar')); } - /** @test */ + #[Test] public function can_use_except_to_limit_multiple_methods() { $options = new ControllerMiddlewareOptions; diff --git a/tests/ControllerMiddlewareTest.php b/tests/ControllerMiddlewareTest.php index 114cca6..66e29e9 100644 --- a/tests/ControllerMiddlewareTest.php +++ b/tests/ControllerMiddlewareTest.php @@ -6,10 +6,11 @@ use Rareloop\Router\ControllerMiddleware; use Rareloop\Router\ControllerMiddlewareOptions; use Rareloop\Router\Test\Middleware\AddHeaderMiddleware; +use PHPUnit\Framework\Attributes\Test; class ControllerMiddlewareTest extends TestCase { - /** @test */ + #[Test] public function can_retrieve_middleware() { $middleware = new AddHeaderMiddleware('X-Header', 'testing123'); @@ -20,7 +21,7 @@ public function can_retrieve_middleware() $this->assertSame($middleware, $controllerMiddleware->middleware()); } - /** @test */ + #[Test] public function can_retrieve_options() { $middleware = new AddHeaderMiddleware('X-Header', 'testing123'); diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 64f6b91..217ed04 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -3,7 +3,6 @@ namespace Rareloop\Router\Test; use Mockery; -use DI\ContainerBuilder; use PHPUnit\Framework\TestCase; use Rareloop\Router\Controller; use Rareloop\Router\ControllerMiddlewareOptions; @@ -12,13 +11,14 @@ use Rareloop\Router\Test\Controllers\MiddlewareProvidingController; use Rareloop\Router\Test\Middleware\AddHeaderMiddleware; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class ControllerTest extends TestCase { - /** @test */ + #[Test] public function can_add_single_middleware_via_controller() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $request = new ServerRequest([], [], '/test/123', 'GET'); $router = new Router($container); @@ -37,10 +37,10 @@ public function can_add_single_middleware_via_controller() $this->assertSame('testing123', $response->getHeader('X-Header')[0]); } - /** @test */ + #[Test] public function can_resolve_middleware_on_a_controller_using_custom_resolver() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $resolver = $this->createMockMiddlewareResolverWithHeader('X-Header', 'testing123'); $request = new ServerRequest([], [], '/test/123', 'GET'); $router = new Router($container, $resolver); @@ -60,10 +60,10 @@ public function can_resolve_middleware_on_a_controller_using_custom_resolver() $this->assertSame('testing123', $response->getHeader('X-Header')[0]); } - /** @test */ + #[Test] public function can_add_multiple_middleware_as_array_via_controller() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $request = new ServerRequest([], [], '/test/123', 'GET'); $router = new Router($container); @@ -87,7 +87,7 @@ public function can_add_multiple_middleware_as_array_via_controller() $this->assertSame('testing456', $response->getHeader('X-Header-2')[0]); } - /** @test */ + #[Test] public function controller_middleware_method_returns_options() { $controller = new MiddlewareProvidingController; @@ -97,10 +97,10 @@ public function controller_middleware_method_returns_options() $this->assertInstanceOf(ControllerMiddlewareOptions::class, $options); } - /** @test */ + #[Test] public function middleware_can_be_limited_to_methods_using_only() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $controller = new MiddlewareProvidingController; @@ -116,10 +116,10 @@ public function middleware_can_be_limited_to_methods_using_only() $this->assertMiddlewareIsAppliedToMethods($router, $middlewareAppliedToMethods); } - /** @test */ + #[Test] public function middleware_can_be_limited_to_multiple_methods_using_only() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $controller = new MiddlewareProvidingController; @@ -135,10 +135,10 @@ public function middleware_can_be_limited_to_multiple_methods_using_only() $this->assertMiddlewareIsAppliedToMethods($router, $middlewareAppliedToMethods); } - /** @test */ + #[Test] public function middleware_can_be_limited_to_methods_using_except() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $controller = new MiddlewareProvidingController; @@ -154,10 +154,10 @@ public function middleware_can_be_limited_to_methods_using_except() $this->assertMiddlewareIsAppliedToMethods($router, $middlewareAppliedToMethods); } - /** @test */ + #[Test] public function middleware_can_be_limited_to_multiple_methods_using_except() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $controller = new MiddlewareProvidingController; @@ -188,10 +188,10 @@ protected function assertMiddlewareIsAppliedToMethods($router, $middlewareApplie $response = $router->match(new ServerRequest([], [], '/test/' . $method, 'GET')); if ($applied) { - $this->assertTrue($response->hasHeader('X-Header'), '`'.$method.'` should have middleware applied'); + $this->assertTrue($response->hasHeader('X-Header'), '`' . $method . '` should have middleware applied'); $this->assertSame('testing123', $response->getHeader('X-Header')[0]); } else { - $this->assertFalse($response->hasHeader('X-Header'), '`'.$method.'` should not have middleware applied'); + $this->assertFalse($response->hasHeader('X-Header'), '`' . $method . '` should not have middleware applied'); } } } diff --git a/tests/FormattingTest.php b/tests/FormattingTest.php index fa718c3..c0a9dac 100644 --- a/tests/FormattingTest.php +++ b/tests/FormattingTest.php @@ -4,10 +4,11 @@ use PHPUnit\Framework\TestCase; use Rareloop\Router\Helpers\Formatting; +use PHPUnit\Framework\Attributes\Test; class FormattingTest extends TestCase { - /** @test */ + #[Test] public function can_remove_trialing_slash() { $string = 'string/'; @@ -15,7 +16,7 @@ public function can_remove_trialing_slash() $this->assertSame('string', Formatting::removeTrailingSlash($string)); } - /** @test */ + #[Test] public function can_add_trialing_slash() { $string = 'string'; @@ -23,7 +24,7 @@ public function can_add_trialing_slash() $this->assertSame('string/', Formatting::addTrailingSlash($string)); } - /** @test */ + #[Test] public function add_trialing_slash_does_not_produce_duplicates() { $string = 'string/'; @@ -31,7 +32,7 @@ public function add_trialing_slash_does_not_produce_duplicates() $this->assertSame('string/', Formatting::addTrailingSlash($string)); } - /** @test */ + #[Test] public function can_remove_leading_slash() { $string = '/string'; @@ -39,7 +40,7 @@ public function can_remove_leading_slash() $this->assertSame('string', Formatting::removeLeadingSlash($string)); } - /** @test */ + #[Test] public function can_add_leading_slash() { $string = 'string'; @@ -47,7 +48,7 @@ public function can_add_leading_slash() $this->assertSame('/string', Formatting::addLeadingSlash($string)); } - /** @test */ + #[Test] public function add_leading_slash_does_not_produce_duplicates() { $string = '/string'; diff --git a/tests/ResponseFactoryTest.php b/tests/ResponseFactoryTest.php index 3cc2eaf..d596149 100644 --- a/tests/ResponseFactoryTest.php +++ b/tests/ResponseFactoryTest.php @@ -10,6 +10,7 @@ use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\Response\TextResponse; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class ResponseFactoryTest extends TestCase { @@ -24,7 +25,7 @@ public function setUp(): void $this->request = new ServerRequest([], [], '/test/123', 'GET'); } - /** @test */ + #[Test] public function when_passed_a_response_instance_the_same_object_is_returned() { $response = new TextResponse('Testing', 200); @@ -32,7 +33,7 @@ public function when_passed_a_response_instance_the_same_object_is_returned() $this->assertSame($response, ResponseFactory::create($this->request, $response)); } - /** @test */ + #[Test] public function when_passed_a_non_response_instance_a_response_object_is_returned() { $response = ResponseFactory::create($this->request, 'Testing'); @@ -41,7 +42,7 @@ public function when_passed_a_non_response_instance_a_response_object_is_returne $this->assertSame('Testing', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function when_nothing_is_passed_an_empty_response_object_is_returned() { $response = ResponseFactory::create($this->request); @@ -49,7 +50,7 @@ public function when_nothing_is_passed_an_empty_response_object_is_returned() $this->assertInstanceOf(EmptyResponse::class, $response); } - /** @test */ + #[Test] public function when_a_responsable_object_is_passed_the_response_object_is_returned() { $textResponse = new TextResponse('testing123'); diff --git a/tests/RouteGroupTest.php b/tests/RouteGroupTest.php index b334314..43cc948 100644 --- a/tests/RouteGroupTest.php +++ b/tests/RouteGroupTest.php @@ -6,10 +6,11 @@ use Rareloop\Router\Route; use Rareloop\Router\RouteGroup; use Rareloop\Router\Router; +use PHPUnit\Framework\Attributes\Test; class RouteGroupTest extends TestCase { - /** @test */ + #[Test] public function group_function_is_chainable() { $router = new Router; @@ -17,7 +18,7 @@ public function group_function_is_chainable() $this->assertInstanceOf(Router::class, $router->group('test/123', function () {})); } - /** @test */ + #[Test] public function can_add_get_request_to_a_group() { $router = new Router; @@ -35,7 +36,7 @@ public function can_add_get_request_to_a_group() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_request_to_a_group_with_leading_slash() { $router = new Router; @@ -53,7 +54,7 @@ public function can_add_request_to_a_group_with_leading_slash() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_post_request_to_a_group() { $router = new Router; @@ -71,7 +72,7 @@ public function can_add_post_request_to_a_group() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_put_request_to_a_group() { $router = new Router; @@ -89,7 +90,7 @@ public function can_add_put_request_to_a_group() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_patch_request_to_a_group() { $router = new Router; @@ -107,7 +108,7 @@ public function can_add_patch_request_to_a_group() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_delete_request_to_a_group() { $router = new Router; @@ -125,7 +126,7 @@ public function can_add_delete_request_to_a_group() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_options_request_to_a_group() { $router = new Router; @@ -143,9 +144,7 @@ public function can_add_options_request_to_a_group() $this->assertSame(1, $count); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_macros() { RouteGroup::macro('testFunctionAddedByMacro', function () { @@ -158,9 +157,7 @@ public function can_extend_post_behaviour_with_macros() $this->assertSame('abc123', RouteGroup::testFunctionAddedByMacro()); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_mixin() { RouteGroup::mixin(new RouteGroupMixin); @@ -175,7 +172,7 @@ class RouteGroupMixin { function testFunctionAddedByMixin() { - return function() { + return function () { return 'abc123'; }; } diff --git a/tests/RouteTest.php b/tests/RouteTest.php index c5a7a03..cdfad2f 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -2,15 +2,16 @@ namespace Rareloop\Router\Test; +use Rareloop\Router\Route; +use Rareloop\Router\Router; use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\Test; use Rareloop\Router\Exceptions\RouteNameRedefinedException; -use Rareloop\Router\Route; -use Rareloop\Router\Router; class RouteTest extends TestCase { - /** @test */ + #[Test] public function a_route_can_be_named() { $router = new Router; @@ -20,7 +21,7 @@ public function a_route_can_be_named() $this->assertTrue($router->has('test')); } - /** @test */ + #[Test] public function name_function_is_chainable() { $router = new Router; @@ -28,7 +29,7 @@ public function name_function_is_chainable() $this->assertInstanceOf(Route::class, $router->get('test/123', function () {})->name('test')); } - /** @test */ + #[Test] public function a_route_can_not_be_renamed() { $this->expectException(RouteNameRedefinedException::class); @@ -38,7 +39,7 @@ public function a_route_can_not_be_renamed() $route = $router->get('test/123', function () {})->name('test1')->name('test2'); } - /** @test */ + #[Test] public function where_function_is_chainable() { $router = new Router; @@ -46,7 +47,7 @@ public function where_function_is_chainable() $this->assertInstanceOf(Route::class, $router->get('test/{id}', function () {})->where('id', '[0-9]+')); } - /** @test */ + #[Test] public function where_function_is_chainable_when_passed_an_array() { $router = new Router; @@ -54,7 +55,7 @@ public function where_function_is_chainable_when_passed_an_array() $this->assertInstanceOf(Route::class, $router->get('test/{id}', function () {})->where(['id' => '[0-9]+'])); } - /** @test */ + #[Test] public function where_function_throws_exception_when_no_params_provided() { $this->expectException(InvalidArgumentException::class); @@ -64,7 +65,7 @@ public function where_function_throws_exception_when_no_params_provided() $this->assertInstanceOf(Route::class, $router->get('test/{id}', function () {})->where()); } - /** @test */ + #[Test] public function can_get_route_action_name_when_closure() { $router = new Router; @@ -73,37 +74,35 @@ public function can_get_route_action_name_when_closure() $this->assertSame('Closure', $route->getActionName()); } - /** @test */ + #[Test] public function can_get_route_action_name_when_callable() { $router = new Router; $route = $router->get('test/123', [TestCallableController::class, 'testStatic']); - $this->assertSame(TestCallableController::class.'@testStatic', $route->getActionName()); + $this->assertSame(TestCallableController::class . '@testStatic', $route->getActionName()); } - /** @test */ + #[Test] public function can_get_route_action_name_when_callable_instance() { $router = new Router; $controller = new TestCallableController; $route = $router->get('test/123', [$controller, 'test']); - $this->assertSame(TestCallableController::class.'@test', $route->getActionName()); + $this->assertSame(TestCallableController::class . '@test', $route->getActionName()); } - /** @test */ + #[Test] public function can_get_route_action_name_when_controller_string() { $router = new Router; - $route = $router->get('test/123', TestCallableController::class.'@test'); + $route = $router->get('test/123', TestCallableController::class . '@test'); - $this->assertSame(TestCallableController::class.'@test', $route->getActionName()); + $this->assertSame(TestCallableController::class . '@test', $route->getActionName()); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_macros() { Route::macro('testFunctionAddedByMacro', function () { @@ -116,9 +115,7 @@ public function can_extend_post_behaviour_with_macros() $this->assertSame('abc123', Route::testFunctionAddedByMacro()); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_mixin() { Route::mixin(new RouteMixin); @@ -139,7 +136,7 @@ class RouteMixin { function testFunctionAddedByMixin() { - return function() { + return function () { return 'abc123'; }; } diff --git a/tests/RouterDITest.php b/tests/RouterDITest.php index acbd433..01abe2f 100644 --- a/tests/RouterDITest.php +++ b/tests/RouterDITest.php @@ -10,19 +10,20 @@ use Rareloop\Router\Test\Requests\TestRequest; use Rareloop\Router\Test\Services\TestService; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class RouterDITest extends TestCase { - /** @test */ + #[Test] public function can_pass_a_container_into_constructor() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $this->assertInstanceOf(Router::class, $router); } - /** @test */ + #[Test] public function container_passed_to_constructor_must_be_psr_11_compatible() { $this->expectException(\TypeError::class); @@ -33,10 +34,10 @@ public function container_passed_to_constructor_must_be_psr_11_compatible() $this->assertInstanceOf(Router::class, $router); } - /** @test */ + #[Test] public function route_params_are_injected_into_closure() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $count = 0; @@ -57,10 +58,10 @@ public function route_params_are_injected_into_closure() $this->assertSame('abc', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function typehints_are_injected_into_closure() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $testServiceInstance = new TestService('abc123'); $container->set(TestService::class, $testServiceInstance); @@ -84,10 +85,10 @@ public function typehints_are_injected_into_closure() $this->assertSame('abc', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function typehints_are_injected_into_closure_with_params() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $testServiceInstance = new TestService('abc123'); $container->set(TestService::class, $testServiceInstance); @@ -113,10 +114,10 @@ public function typehints_are_injected_into_closure_with_params() $this->assertSame('abc', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function route_params_are_injected_into_closure_regardless_of_param_order() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $count = 0; @@ -137,12 +138,12 @@ public function route_params_are_injected_into_closure_regardless_of_param_order $this->assertSame('abc', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function reflection_error_is_thrown_when_typehints_cant_be_resolved_from_the_container() { $this->expectException(\ReflectionException::class); - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $router->get('/test/route', function (UndefinedType $test) {}); @@ -151,10 +152,10 @@ public function reflection_error_is_thrown_when_typehints_cant_be_resolved_from_ $response = $router->match($request); } - /** @test */ + #[Test] public function route_params_are_injected_into_controller_class() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $router->get('/posts/{postId}/comments/{commentId}', 'Rareloop\Router\Test\Controllers\TestController@expectsInjectedParams'); @@ -166,10 +167,10 @@ public function route_params_are_injected_into_controller_class() $this->assertSame('$postId: 1 $commentId: 2', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function typehints_are_injected_into_controller_class() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $testServiceInstance = new TestService('abc123'); $container->set(TestService::class, $testServiceInstance); @@ -184,10 +185,10 @@ public function typehints_are_injected_into_controller_class() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function typehints_are_injected_into_controller_class_with_params() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $testServiceInstance = new TestService('abc123'); $container->set(TestService::class, $testServiceInstance); @@ -202,10 +203,10 @@ public function typehints_are_injected_into_controller_class_with_params() $this->assertSame('$postId: 1 $commentId: 2 TestService: abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_inject_request_object() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $request = new ServerRequest([], [], '/test/route', 'GET'); $router = new Router($container); $count = 0; @@ -228,10 +229,10 @@ public function can_inject_request_object() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_inject_request_object_with_a_body() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $request = new ServerRequest([], [], '/test/route', 'POST', 'php://input', [], [], [], 'post body'); $router = new Router($container); $count = 0; @@ -255,10 +256,10 @@ public function can_inject_request_object_with_a_body() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_inject_request_sub_class() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $request = new ServerRequest([], [], '/test/route', 'GET'); $router = new Router($container); @@ -282,10 +283,10 @@ public function can_inject_request_sub_class() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function constructor_params_are_injected_into_controller_class() { - $container = ContainerBuilder::buildDevContainer(); + $container = new \DI\Container(); $router = new Router($container); $testServiceInstance = new TestService('abc123'); $container->set(TestService::class, $testServiceInstance); diff --git a/tests/RouterMiddlewareTest.php b/tests/RouterMiddlewareTest.php index 8f6e2e3..c42eae5 100644 --- a/tests/RouterMiddlewareTest.php +++ b/tests/RouterMiddlewareTest.php @@ -14,10 +14,11 @@ use Rareloop\Router\Test\Controllers\MiddlewareProvidingController; use Rareloop\Router\Test\Middleware\AddHeaderMiddleware; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class RouterMiddlewareTest extends TestCase { - /** @test */ + #[Test] public function can_add_middleware_as_a_closure_to_a_route() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -43,7 +44,7 @@ public function can_add_middleware_as_a_closure_to_a_route() $this->assertSame('value', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_add_middleware_as_an_object_to_a_route() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -63,7 +64,7 @@ public function can_add_middleware_as_an_object_to_a_route() $this->assertSame('value', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_add_multiple_middleware_to_a_route_in_successive_calls() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -82,7 +83,7 @@ public function can_add_multiple_middleware_to_a_route_in_successive_calls() $this->assertSame('123', $response->getHeader('X-Key2')[0]); } - /** @test */ + #[Test] public function can_add_multiple_middleware_to_a_route_in_a_single_call() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -102,7 +103,7 @@ public function can_add_multiple_middleware_to_a_route_in_a_single_call() $this->assertSame('123', $response->getHeader('X-Key2')[0]); } - /** @test */ + #[Test] public function can_add_multiple_middleware_to_a_route_as_an_array() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -122,7 +123,7 @@ public function can_add_multiple_middleware_to_a_route_as_an_array() $this->assertSame('123', $response->getHeader('X-Key2')[0]); } - /** @test */ + #[Test] public function can_add_middleware_to_a_group() { $request = new ServerRequest([], [], '/all', 'GET'); @@ -146,7 +147,7 @@ public function can_add_middleware_to_a_group() $this->assertSame('abc', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_add_single_middleware_to_a_group_without_wrapping_in_array() { $request = new ServerRequest([], [], '/all', 'GET'); @@ -170,7 +171,7 @@ public function can_add_single_middleware_to_a_group_without_wrapping_in_array() $this->assertSame('abc', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_add_base_middleware_to_be_applied_to_all_routes() { $router = new Router; @@ -205,7 +206,7 @@ public function can_add_base_middleware_to_be_applied_to_all_routes() $this->assertSame('abc', $response2->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_resolve_middleware_on_a_route_using_a_custom_resolver() { $resolver = $this->createMockMiddlewareResolverWithHeader('X-Key', 'abc'); @@ -221,7 +222,7 @@ public function can_resolve_middleware_on_a_route_using_a_custom_resolver() $this->assertSame('abc', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_resolve_middleware_on_a_group_using_a_custom_resolver() { $resolver = $this->createMockMiddlewareResolverWithHeader('X-Key', 'abc'); @@ -239,7 +240,7 @@ public function can_resolve_middleware_on_a_group_using_a_custom_resolver() $this->assertSame('abc', $response->getHeader('X-Key')[0]); } - /** @test */ + #[Test] public function can_resolve_global_middleware_using_a_custom_resolver() { $resolver = $this->createMockMiddlewareResolverWithHeader('X-Key', 'abc'); diff --git a/tests/RouterParamsTest.php b/tests/RouterParamsTest.php index 63ac8e6..976ccc0 100644 --- a/tests/RouterParamsTest.php +++ b/tests/RouterParamsTest.php @@ -4,10 +4,11 @@ use PHPUnit\Framework\TestCase; use Rareloop\Router\RouteParams; +use PHPUnit\Framework\Attributes\Test; class RouterParamsTest extends TestCase { - /** @test */ + #[Test] public function can_get_param_by_key() { $params = new RouteParams(['key' => 'value']); @@ -15,7 +16,7 @@ public function can_get_param_by_key() $this->assertSame('value', $params->key); } - /** @test */ + #[Test] public function can_iterate_all_keys_and_values() { $params = new RouteParams([ @@ -36,7 +37,7 @@ public function can_iterate_all_keys_and_values() $this->assertSame(['value1', 'value2', 'value3'], $values); } - /** @test */ + #[Test] public function return_null_when_a_key_is_not_found() { $params = new RouteParams(['key' => 'value']); @@ -44,7 +45,7 @@ public function return_null_when_a_key_is_not_found() $this->assertNull($params->invalid); } - /** @test */ + #[Test] public function can_get_params_as_array() { $data = ['key1' => 'value1', 'key2' => 'value2']; diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 16184f7..bde398d 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -18,10 +18,11 @@ use Laminas\Diactoros\Response; use Laminas\Diactoros\Response\TextResponse; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; class RouterTest extends TestCase { - /** @test */ + #[Test] public function map_returns_a_route_object() { $router = new Router; @@ -33,7 +34,7 @@ public function map_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function map_accepts_lowercase_verbs() { $router = new Router; @@ -43,7 +44,7 @@ public function map_accepts_lowercase_verbs() $this->assertSame(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], $route->getMethods()); } - /** @test */ + #[Test] public function get_returns_a_route_object() { $router = new Router; @@ -55,7 +56,7 @@ public function get_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function post_returns_a_route_object() { $router = new Router; @@ -67,7 +68,7 @@ public function post_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function patch_returns_a_route_object() { $router = new Router; @@ -79,7 +80,7 @@ public function patch_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function put_returns_a_route_object() { $router = new Router; @@ -91,7 +92,7 @@ public function put_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function delete_returns_a_route_object() { $router = new Router; @@ -103,7 +104,7 @@ public function delete_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function options_returns_a_route_object() { $router = new Router; @@ -115,7 +116,7 @@ public function options_returns_a_route_object() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function map_removes_trailing_slash_from_uri() { $router = new Router; @@ -127,7 +128,7 @@ public function map_removes_trailing_slash_from_uri() $this->assertSame('/test/123', $route->getUri()); } - /** @test */ + #[Test] public function no_return_from_route_action_results_in_a_204_status_code() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -143,7 +144,7 @@ public function no_return_from_route_action_results_in_a_204_status_code() $this->assertSame(204, $response->getStatusCode()); } - /** @test */ + #[Test] public function leading_slash_is_optional_when_creating_a_route() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -159,7 +160,7 @@ public function leading_slash_is_optional_when_creating_a_route() $this->assertInstanceOf(ResponseInterface::class, $response); } - /** @test */ + #[Test] public function matching_root_path_does_not_trigger_error() { $request = new ServerRequest([], [], '/', 'GET'); @@ -174,7 +175,7 @@ public function matching_root_path_does_not_trigger_error() $this->assertSame(0, $count); } - /** @test */ + #[Test] public function can_match_a_route_for_root_path() { $request = new ServerRequest([], [], '/', 'GET'); @@ -189,7 +190,7 @@ public function can_match_a_route_for_root_path() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function match_returns_a_response_object() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -207,7 +208,7 @@ public function match_returns_a_response_object() $this->assertInstanceOf(ResponseInterface::class, $response); } - /** @test */ + #[Test] public function match_does_not_mutate_returned_response_object() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -222,7 +223,7 @@ public function match_does_not_mutate_returned_response_object() $this->assertSame($response, $routerResponse); } - /** @test */ + #[Test] public function match_returns_a_404_response_object_when_route_is_not_found() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -234,7 +235,7 @@ public function match_returns_a_404_response_object_when_route_is_not_found() $this->assertSame(404, $response->getStatusCode()); } - /** @test */ + #[Test] public function match_works_with_a_closure() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -252,7 +253,7 @@ public function match_works_with_a_closure() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_uri_with_trailing_when_route_has_been_defined_without_trailing_slash() { $request = new ServerRequest([], [], '/test/123/', 'GET'); @@ -270,7 +271,7 @@ public function match_uri_with_trailing_when_route_has_been_defined_without_trai $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_uri_with_trailing_when_route_has_been_defined_with_trailing_slash() { $request = new ServerRequest([], [], '/test/123/', 'GET'); @@ -288,7 +289,7 @@ public function match_uri_with_trailing_when_route_has_been_defined_with_trailin $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_uri_without_trailing_when_route_has_been_defined_without_trailing_slash() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -306,7 +307,7 @@ public function match_uri_without_trailing_when_route_has_been_defined_without_t $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_uri_without_trailing_when_route_has_been_defined_with_trailing_slash() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -324,7 +325,7 @@ public function match_uri_without_trailing_when_route_has_been_defined_with_trai $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_works_with_a_class_and_method_string() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -336,7 +337,7 @@ public function match_works_with_a_class_and_method_string() $this->assertSame('Hello World', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function match_throws_exception_with_invalid_class_and_string_method() { $this->expectException(RouteClassStringParseException::class); @@ -346,7 +347,7 @@ public function match_throws_exception_with_invalid_class_and_string_method() $route = $router->get('/test/123', 'Rareloop\Router\Test\Controllers\TestController:returnHelloWorld'); } - /** @test */ + #[Test] public function match_throws_exception_when_class_and_string_method_contains_an_unfound_class() { $this->expectException(RouteClassStringControllerNotFoundException::class); @@ -356,7 +357,7 @@ public function match_throws_exception_when_class_and_string_method_contains_an_ $route = $router->get('/test/123', 'Rareloop\Router\Test\Controllers\UndefinedController@returnHelloWorld'); } - /** @test */ + #[Test] public function match_throws_exception_when_class_and_string_method_contains_an_unfound_method() { $this->expectException(RouteClassStringMethodNotFoundException::class); @@ -366,7 +367,7 @@ public function match_throws_exception_when_class_and_string_method_contains_an_ $route = $router->get('/test/123', 'Rareloop\Router\Test\Controllers\TestController@undefinedMethod'); } - /** @test */ + #[Test] public function params_are_parsed_and_passed_into_callback_function() { $request = new ServerRequest([], [], '/posts/123/comments/abc', 'GET'); @@ -384,7 +385,7 @@ public function params_are_parsed_and_passed_into_callback_function() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function params_are_parsed_and_passed_into_callback_function_when_surrounded_by_whitespace() { $request = new ServerRequest([], [], '/posts/123/comments/abc', 'GET'); @@ -402,7 +403,7 @@ public function params_are_parsed_and_passed_into_callback_function_when_surroun $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_regex_constraints_on_params_as_key_value() { $matchingRequest = new ServerRequest([], [], '/posts/123/comments', 'GET'); @@ -419,7 +420,7 @@ public function can_add_regex_constraints_on_params_as_key_value() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_multiple_regex_constraints_on_params_as_key_value() { $matchingRequest = new ServerRequest([], [], '/posts/123/comments/abc', 'GET'); @@ -436,7 +437,7 @@ public function can_add_multiple_regex_constraints_on_params_as_key_value() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_regex_constraints_on_params_as_array() { $matchingRequest = new ServerRequest([], [], '/posts/123/comments', 'GET'); @@ -453,7 +454,7 @@ public function can_add_regex_constraints_on_params_as_array() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_add_multiple_regex_constraints_on_params_as_array() { $matchingRequest = new ServerRequest([], [], '/posts/123/comments/abc', 'GET'); @@ -473,7 +474,7 @@ public function can_add_multiple_regex_constraints_on_params_as_array() $this->assertSame(1, $count); } - /** @test */ + #[Test] public function can_provide_optional_params() { $matchingRequest1 = new ServerRequest([], [], '/posts/123', 'GET'); @@ -494,7 +495,7 @@ public function can_provide_optional_params() $this->assertSame(2, $count); } - /** @test */ + #[Test] public function can_generate_canonical_uri_with_trailing_slash_for_named_route() { $router = new Router; @@ -504,7 +505,7 @@ public function can_generate_canonical_uri_with_trailing_slash_for_named_route() $this->assertSame('/posts/all/', $router->url('test.name')); } - /** @test */ + #[Test] public function can_generate_canonical_uri_with_trailing_slash_for_named_route_with_params() { $router = new Router; @@ -514,7 +515,7 @@ public function can_generate_canonical_uri_with_trailing_slash_for_named_route_w $this->assertSame('/posts/123/comments/', $router->url('test.name', ['id' => 123])); } - /** @test */ + #[Test] public function url_throws_exception_when_provided_params_fail_the_regex_constraints() { $this->expectException(RouteParamFailedConstraintException::class); @@ -528,7 +529,7 @@ public function url_throws_exception_when_provided_params_fail_the_regex_constra $router->url('test.name', ['id' => 123]); } - /** @test */ + #[Test] public function generating_a_url_for_a_named_route_that_doesnt_exist_throws_an_exception() { $this->expectException(NamedRouteNotFoundException::class); @@ -538,7 +539,7 @@ public function generating_a_url_for_a_named_route_that_doesnt_exist_throws_an_e $router->url('test.name'); } - /** @test */ + #[Test] public function can_generate_canonical_uri_after_match_has_been_called() { $router = new Router; @@ -550,7 +551,7 @@ public function can_generate_canonical_uri_after_match_has_been_called() $this->assertSame('/posts/all/', $router->url('test.name')); } - /** @test */ + #[Test] public function adding_routes_after_calling_url_throws_an_exception() { $this->expectException(TooLateToAddNewRouteException::class); @@ -563,7 +564,7 @@ public function adding_routes_after_calling_url_throws_an_exception() $route = $router->get('another/url', function () {}); } - /** @test */ + #[Test] public function adding_routes_after_calling_match_throws_an_exception() { $this->expectException(TooLateToAddNewRouteException::class); @@ -577,7 +578,7 @@ public function adding_routes_after_calling_match_throws_an_exception() $route = $router->get('another/url', function () {}); } - /** @test */ + #[Test] public function can_add_routes_in_a_group() { $request = new ServerRequest([], [], '/prefix/all', 'GET'); @@ -599,7 +600,7 @@ public function can_add_routes_in_a_group() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_add_routes_in_a_group_using_array_as_first_param() { $request = new ServerRequest([], [], '/prefix/all', 'GET'); @@ -621,7 +622,7 @@ public function can_add_routes_in_a_group_using_array_as_first_param() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_add_routes_in_a_group_using_array_as_first_param_with_no_prefix() { $request = new ServerRequest([], [], '/all', 'GET'); @@ -643,7 +644,7 @@ public function can_add_routes_in_a_group_using_array_as_first_param_with_no_pre $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function group_prefixes_work_with_leading_slash() { $request = new ServerRequest([], [], '/prefix/all', 'GET'); @@ -665,7 +666,7 @@ public function group_prefixes_work_with_leading_slash() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function group_prefixes_work_with_trailing_slash() { $request = new ServerRequest([], [], '/prefix/all', 'GET'); @@ -687,7 +688,7 @@ public function group_prefixes_work_with_trailing_slash() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_add_routes_in_nested_groups() { $request = new ServerRequest([], [], '/prefix/prefix2/all', 'GET'); @@ -714,7 +715,7 @@ public function can_add_routes_in_nested_groups() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_add_routes_in_nested_groups_with_array_syntax() { $request = new ServerRequest([], [], '/prefix/prefix2/all', 'GET'); @@ -741,7 +742,7 @@ public function can_add_routes_in_nested_groups_with_array_syntax() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_set_base_path() { $request = new ServerRequest([], [], '/base-path/prefix/all', 'GET'); @@ -760,7 +761,7 @@ public function can_set_base_path() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_set_base_path_without_trailing_slash() { $request = new ServerRequest([], [], '/base-path/prefix/all', 'GET'); @@ -779,7 +780,7 @@ public function can_set_base_path_without_trailing_slash() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_set_base_path_without_leading_slash() { $request = new ServerRequest([], [], '/base-path/prefix/all', 'GET'); @@ -798,7 +799,7 @@ public function can_set_base_path_without_leading_slash() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_set_base_path_without_leading_or_trailing_slash() { $request = new ServerRequest([], [], '/base-path/prefix/all', 'GET'); @@ -817,7 +818,7 @@ public function can_set_base_path_without_leading_or_trailing_slash() $this->assertSame('abc123', $response->getBody()->getContents()); } - /** @test */ + #[Test] public function can_update_base_path_after_match_has_been_called() { $router = new Router; @@ -843,7 +844,7 @@ public function can_update_base_path_after_match_has_been_called() $this->assertSame('abc123', $response2->getBody()->getContents()); } - /** @test */ + #[Test] public function can_add_middleware_as_a_closure_to_a_route() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -868,7 +869,7 @@ public function can_add_middleware_as_a_closure_to_a_route() $this->assertSame('value', $response->getHeader('X-key')[0]); } - /** @test */ + #[Test] public function can_get_currently_matched_route() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -887,7 +888,7 @@ public function can_get_currently_matched_route() $this->assertSame($route, $router->currentRoute()); } - /** @test */ + #[Test] public function can_get_currently_matched_route_name() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -906,7 +907,7 @@ public function can_get_currently_matched_route_name() $this->assertSame('test123', $router->currentRouteName()); } - /** @test */ + #[Test] public function current_route_name_returns_null_when_match_not_yet_called() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -919,7 +920,7 @@ public function current_route_name_returns_null_when_match_not_yet_called() $this->assertSame(null, $router->currentRouteName()); } - /** @test */ + #[Test] public function current_route_name_returns_null_when_matched_route_has_no_name() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -934,7 +935,7 @@ public function current_route_name_returns_null_when_matched_route_has_no_name() $this->assertSame(null, $router->currentRouteName()); } - /** @test */ + #[Test] public function can_get_list_of_registered_routes() { $router = new Router; @@ -948,9 +949,7 @@ public function can_get_list_of_registered_routes() $this->assertContains($route2, $routes); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_macros() { Router::macro('testFunctionAddedByMacro', function () { @@ -963,9 +962,7 @@ public function can_extend_post_behaviour_with_macros() $this->assertSame('abc123', Router::testFunctionAddedByMacro()); } - /** - * @test - */ + #[Test] public function can_extend_post_behaviour_with_mixin() { Router::mixin(new RouterMixin); @@ -980,7 +977,7 @@ class RouterMixin { function testFunctionAddedByMixin() { - return function() { + return function () { return 'abc123'; }; } diff --git a/tests/TypeHintRequestResolverTest.php b/tests/TypeHintRequestResolverTest.php index 31efbef..de5e3d5 100644 --- a/tests/TypeHintRequestResolverTest.php +++ b/tests/TypeHintRequestResolverTest.php @@ -3,12 +3,13 @@ namespace Rareloop\Router\Test; use PHPUnit\Framework\TestCase; -use Rareloop\Router\TypeHintRequestResolver; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\Attributes\Test; +use Rareloop\Router\TypeHintRequestResolver; class TypeHintRequestResolverTest extends TestCase { - /** @test */ + #[Test] public function returns_resolved_parameters_when_no_request_is_set() { $reflectionFunction = new \ReflectionFunction(function () {}); @@ -20,7 +21,7 @@ public function returns_resolved_parameters_when_no_request_is_set() $this->assertSame($resolvedParameters, $params); } - /** @test */ + #[Test] public function can_resolve_a_request() { $request = new ServerRequest([], [], '/injected', 'GET'); @@ -33,7 +34,7 @@ public function can_resolve_a_request() $this->assertSame('/injected', $params[0]->getUri()->getPath()); } - /** @test */ + #[Test] public function does_not_attempt_to_resolve_params_that_have_already_been_resolved() { $preResolvedRequest = new ServerRequest([], [], '/pre/resolved', 'GET');