From 9640c2f47b2549416424e785b5643c63505f2011 Mon Sep 17 00:00:00 2001 From: spiralbot Date: Tue, 7 Jan 2025 13:33:35 +0000 Subject: [PATCH] prepare release --- composer.json | 10 +-- src/CoreHandler.php | 4 -- src/Route.php | 9 ++- src/Router.php | 2 +- src/Traits/PipelineTrait.php | 24 +------ src/UriHandler.php | 2 +- tests/BaseTestCase.php | 13 ++-- tests/BaseTestingCase.php | 40 ------------ tests/CallableTest.php | 26 ++++---- tests/ContainerScopeTest.php | 2 +- tests/ControllerTest.php | 40 ++++++------ tests/CoreTest.php | 22 +++---- tests/DefaultPatternRegistryTest.php | 11 ++-- tests/Fixtures/TestRouterBootloader.php | 33 ---------- tests/GroupTest.php | 8 +-- tests/HostsTest.php | 16 +++-- .../Configurator/RouteConfiguratorTest.php | 36 +++++----- .../Configurator/RoutingConfiguratorTest.php | 36 +++++----- tests/Loader/DelegatingLoaderTest.php | 26 ++++---- tests/Loader/LoaderRegistryTest.php | 16 ++--- tests/Loader/PhpFileLoaderTest.php | 14 ++-- tests/MiddlewareTest.php | 65 +++++++++++-------- tests/MultipleActionsTest.php | 12 ++-- tests/NamespacedTest.php | 14 ++-- tests/PatternsTests.php | 22 +++---- tests/PipelineFactoryTest.php | 9 ++- tests/RegistryTest.php | 8 +-- tests/RouteGroupTest.php | 44 ++++++------- tests/RouteTest.php | 9 ++- tests/RouterFactoryTrait.php | 34 ---------- tests/RouterTest.php | 12 ++-- tests/SingleActionTest.php | 30 ++++----- tests/SubdomainTest.php | 12 ++-- tests/Targets/ActionTargetTest.php | 42 +++++++----- tests/Targets/ControllerTargetTest.php | 38 +++++++---- tests/Targets/GroupTargetTest.php | 24 ++++--- tests/Targets/NamespacedTargetTest.php | 28 ++++---- tests/UriTest.php | 21 +++--- 38 files changed, 364 insertions(+), 450 deletions(-) delete mode 100644 tests/BaseTestingCase.php delete mode 100644 tests/Fixtures/TestRouterBootloader.php delete mode 100644 tests/RouterFactoryTrait.php diff --git a/composer.json b/composer.json index 711023f..a924496 100644 --- a/composer.json +++ b/composer.json @@ -35,12 +35,12 @@ "require": { "php": ">=8.1", "ext-json": "*", - "spiral/core": "^3.15", - "spiral/hmvc": "^3.15", - "spiral/http": "^3.15", - "spiral/interceptors": "^3.15", + "spiral/core": "^3.14.9", + "spiral/hmvc": "^3.14.9", + "spiral/http": "^3.14.9", + "spiral/interceptors": "^3.14.9", "cocur/slugify": "^3.2 || ^4.0", - "spiral/telemetry": "^3.15", + "spiral/telemetry": "^3.14.9", "doctrine/inflector": "^1.4|^2.0", "psr/event-dispatcher": "^1.0" }, diff --git a/src/CoreHandler.php b/src/CoreHandler.php index 35afa66..1624ee7 100644 --- a/src/CoreHandler.php +++ b/src/CoreHandler.php @@ -6,7 +6,6 @@ use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface; use Spiral\Core\CoreInterface; @@ -125,9 +124,6 @@ public function handle(Request $request): Response new CallContext( Target::fromPair($controller, $action), $parameters, - [ - ServerRequestInterface::class => $request, - ], ), ), attributes: [ diff --git a/src/Route.php b/src/Route.php index 67cd6dc..270c79f 100644 --- a/src/Route.php +++ b/src/Route.php @@ -13,7 +13,6 @@ use Spiral\Http\CallableHandler; use Spiral\Router\Exception\RouteException; use Spiral\Router\Exception\TargetException; -use Spiral\Router\Traits\LazyPipelineTrait; use Spiral\Router\Traits\PipelineTrait; /** @@ -91,7 +90,7 @@ public function withContainer(ContainerInterface $container): ContainerizedInter $route->target = clone $route->target; } - $route->pipeline = $route->makeLazyPipeline(); + $route->pipeline = $route->makePipeline(); return $route; } @@ -130,9 +129,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface */ protected function requestHandler(): RequestHandlerInterface { - $this->hasContainer() or throw new RouteException( - 'Unable to configure route pipeline without associated container.', - ); + if (!$this->hasContainer()) { + throw new RouteException('Unable to configure route pipeline without associated container'); + } if ($this->target instanceof TargetInterface) { try { diff --git a/src/Router.php b/src/Router.php index 84dbcb5..cf8dbb4 100644 --- a/src/Router.php +++ b/src/Router.php @@ -67,7 +67,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface return $this->tracer->trace( name: 'Routing', - callback: function (SpanInterface $span) use ($request): ResponseInterface { + callback: function (SpanInterface $span) use ($request) { try { $route = $this->matchRoute($request, $routeName); } catch (RouteException $e) { diff --git a/src/Traits/PipelineTrait.php b/src/Traits/PipelineTrait.php index 32c5ad7..dd43f80 100644 --- a/src/Traits/PipelineTrait.php +++ b/src/Traits/PipelineTrait.php @@ -7,7 +7,6 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Http\Server\MiddlewareInterface; use Spiral\Core\Container\Autowire; -use Spiral\Http\LazyPipeline; use Spiral\Http\Pipeline; use Spiral\Router\Exception\RouteException; use Spiral\Router\PipelineFactory; @@ -20,7 +19,7 @@ trait PipelineTrait { use ContainerTrait; - protected Pipeline|LazyPipeline|null $pipeline = null; + protected ?Pipeline $pipeline = null; /** @psalm-var array */ protected array $middleware = []; @@ -54,7 +53,7 @@ public function withMiddleware(...$middleware): RouteInterface } if ($route->pipeline !== null) { - $route->pipeline = $route->makeLazyPipeline(); + $route->pipeline = $route->makePipeline(); } return $route; @@ -74,8 +73,6 @@ public function withPipeline(Pipeline $pipeline): static * Get associated route pipeline. * * @throws RouteException - * - * @deprecated Will be removed in Spiral v4.0. Use {@see makeLazyPipeline()} instead. */ protected function makePipeline(): Pipeline { @@ -88,21 +85,4 @@ protected function makePipeline(): Pipeline throw new RouteException($e->getMessage(), $e->getCode(), $e); } } - - /** - * Get associated route pipeline. - * - * @throws RouteException - */ - protected function makeLazyPipeline(): LazyPipeline - { - \assert($this->container !== null); - try { - /** @var LazyPipeline $pipeline */ - $pipeline = $this->container->get(LazyPipeline::class); - return $pipeline->withMiddleware(...$this->middleware); - } catch (ContainerExceptionInterface $e) { - throw new RouteException($e->getMessage(), $e->getCode(), $e); - } - } } diff --git a/src/UriHandler.php b/src/UriHandler.php index 354648b..e8961a2 100644 --- a/src/UriHandler.php +++ b/src/UriHandler.php @@ -182,7 +182,7 @@ public function match(UriInterface $uri, array $defaults): ?array } $matches = \array_intersect_key( - \array_filter($matches, static fn (string $value): bool => $value !== ''), + \array_filter($matches, static fn (string $value) => $value !== ''), $this->options ); diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 48ba550..02083e3 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -37,11 +37,6 @@ abstract class BaseTestCase extends TestCase protected Container $container; protected Router $router; - protected function getContainer(): Container - { - return $this->container; - } - protected function setUp(): void { $this->initContainer(); @@ -54,11 +49,11 @@ protected function makeRouter(string $basePath = '', ?EventDispatcherInterface $ $basePath, new UriHandler( new UriFactory(), - new Slugify(), + new Slugify() ), $this->container, $dispatcher, - new NullTracer($this->container), + new NullTracer($this->container) ); } @@ -93,8 +88,8 @@ private function initContainer(): void new LoaderRegistry([ new PhpFileLoader($this->container, $this->container), new TestLoader(), - ]), - ), + ]) + ) ); $this->container->bind(HandlerInterface::class, Core::class); diff --git a/tests/BaseTestingCase.php b/tests/BaseTestingCase.php deleted file mode 100644 index 3eb4e58..0000000 --- a/tests/BaseTestingCase.php +++ /dev/null @@ -1,40 +0,0 @@ -router = $this->getContainer()->get(RouterInterface::class); - } - - /** - * @throws \ReflectionException - */ - protected function getProperty(object $object, string $property): mixed - { - $r = new \ReflectionObject($object); - - return $r->getProperty($property)->getValue($object); - } -} diff --git a/tests/CallableTest.php b/tests/CallableTest.php index 3c5ce9c..d283c53 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -16,12 +16,12 @@ public function testFunctionRoute(): void $router = $this->makeRouter(); $router->setRoute( 'action', - new Route('/something', static fn(): string => 'hello world') + new Route('/something', fn() => 'hello world') ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); } public function testObjectRoute(): void @@ -33,8 +33,8 @@ public function testObjectRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('invoked', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('invoked', (string)$response->getBody()); } public function testObjectViaContainerRoute(): void @@ -46,8 +46,8 @@ public function testObjectViaContainerRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('invoked', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('invoked', (string)$response->getBody()); } public function testHandlerRoute(): void @@ -59,8 +59,8 @@ public function testHandlerRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('handler', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('handler', (string)$response->getBody()); } public function testHandlerViaContainerRoute(): void @@ -72,8 +72,8 @@ public function testHandlerViaContainerRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('handler', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('handler', (string)$response->getBody()); } public function testInvalidTarget(): void @@ -87,7 +87,7 @@ public function testInvalidTarget(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/something'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('handler', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('handler', (string)$response->getBody()); } } diff --git a/tests/ContainerScopeTest.php b/tests/ContainerScopeTest.php index b2bf9c7..c74cd66 100644 --- a/tests/ContainerScopeTest.php +++ b/tests/ContainerScopeTest.php @@ -15,7 +15,7 @@ use Spiral\Tests\Router\Fixtures\UserContextController; use Spiral\Tests\Router\Stub\IdentityScopedMiddleware; -class ContainerScopeTest extends BaseTestingCase +class ContainerScopeTest extends \Spiral\Testing\TestCase { public function defineBootloaders(): array { diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 0d76e73..4005708 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -42,16 +42,16 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/echo'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('echoed', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('echoed', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/id/888'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('888', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('888', (string)$response->getBody()); } public function testOptionalParam(): void @@ -63,22 +63,22 @@ public function testOptionalParam(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/default'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('default', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('default', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/default/123'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('123', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('123', (string)$response->getBody()); } public function testFallbackHandler(): void { $target = new Action(TestController::class, 'default'); - $this->getContainer()->removeBinding(HandlerInterface::class); - $this->getContainer()->removeBinding(CoreInterface::class); + $this->container->removeBinding(HandlerInterface::class); + $this->container->removeBinding(CoreInterface::class); - $core = $target->getHandler($this->getContainer(), []); - $handler = (fn(CoreHandler $core): HandlerInterface|CoreInterface => $core->core)->call($core, $core); + $core = $target->getHandler($this->container, []); + $handler = (fn(CoreHandler $core) => $core->core)->call($core, $core); self::assertInstanceOf(AutowireHandler::class, $handler); } @@ -92,12 +92,12 @@ public function testOptionalParamWithDefaultInt(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('int: 1', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('int: 1', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt/123'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('string: 123', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('string: 123', (string)$response->getBody()); } public function testUriGeneration(): void @@ -109,10 +109,10 @@ public function testUriGeneration(): void ); $uri = $router->uri('action/test'); - self::assertSame('/test', $uri->getPath()); + $this->assertSame('/test', $uri->getPath()); $uri = $router->uri('action/id', ['id' => 100]); - self::assertSame('/id/100', $uri->getPath()); + $this->assertSame('/id/100', $uri->getPath()); } public function testClientException(): void diff --git a/tests/CoreTest.php b/tests/CoreTest.php index 33760ad..7622a4d 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -43,7 +43,7 @@ public function testAutoCore(): void $action = new Action(TestController::class, 'test'); $handler = $action->getHandler($this->getContainer(), []); - self::assertInstanceOf(CoreHandler::class, $handler); + $this->assertInstanceOf(CoreHandler::class, $handler); } public function testWithAutoCore(): void @@ -53,11 +53,11 @@ public function testWithAutoCore(): void $action = $action->withCore(new TestCore($this->getContainer()->get(CoreInterface::class))); $handler = $action->getHandler($this->getContainer(), []); - self::assertInstanceOf(CoreHandler::class, $handler); + $this->assertInstanceOf(CoreHandler::class, $handler); $result = $handler->handle(new ServerRequest('GET', '')); - self::assertSame('@wrapped.hello world', (string)$result->getBody()); + $this->assertSame('@wrapped.hello world', (string)$result->getBody()); } public function testErrAction(): void @@ -70,7 +70,7 @@ public function testErrAction(): void $action = $action->withCore(new TestCore($this->getContainer()->get(CoreInterface::class))); $handler = $action->getHandler($this->getContainer(), []); - self::assertInstanceOf(CoreHandler::class, $handler); + $this->assertInstanceOf(CoreHandler::class, $handler); $handler->handle(new ServerRequest('GET', '')); } @@ -80,11 +80,11 @@ public function testRSP(): void $action = new Action(TestController::class, 'rsp'); $handler = $action->getHandler($this->getContainer(), []); - self::assertInstanceOf(CoreHandler::class, $handler); + $this->assertInstanceOf(CoreHandler::class, $handler); $result = $handler->handle(new ServerRequest('GET', '')); - self::assertSame('rspbuf', (string)$result->getBody()); + $this->assertSame('rspbuf', (string)$result->getBody()); } public function testJson(): void @@ -92,12 +92,12 @@ public function testJson(): void $action = new Action(TestController::class, 'json'); $handler = $action->getHandler($this->getContainer(), []); - self::assertInstanceOf(CoreHandler::class, $handler); + $this->assertInstanceOf(CoreHandler::class, $handler); $result = $handler->handle(new ServerRequest('GET', '')); - self::assertSame(301, $result->getStatusCode()); - self::assertSame('{"status":301,"msg":"redirect"}', (string)$result->getBody()); + $this->assertSame(301, $result->getStatusCode()); + $this->assertSame('{"status":301,"msg":"redirect"}', (string)$result->getBody()); } public function testForbidden(): void @@ -138,10 +138,10 @@ public function testRESTFul(): void $action = new Action(TestController::class, 'Target', Action::RESTFUL); $r = $action->getHandler($this->getContainer(), [])->handle(new ServerRequest('POST', '')); - self::assertSame('POST', (string)$r->getBody()); + $this->assertSame('POST', (string)$r->getBody()); $r = $action->getHandler($this->getContainer(), [])->handle(new ServerRequest('DELETE', '')); - self::assertSame('DELETE', (string)$r->getBody()); + $this->assertSame('DELETE', (string)$r->getBody()); } } diff --git a/tests/DefaultPatternRegistryTest.php b/tests/DefaultPatternRegistryTest.php index 4941512..8f986e5 100644 --- a/tests/DefaultPatternRegistryTest.php +++ b/tests/DefaultPatternRegistryTest.php @@ -20,9 +20,12 @@ public function testAll(): void $registry->register('foo', '\d+'); $registry->register('bar', '\d+'); - self::assertSame(self::DEFAULT_PATTERNS + [ - 'foo' => '\d+', - 'bar' => '\d+' - ], $registry->all()); + $this->assertSame( + self::DEFAULT_PATTERNS + [ + 'foo' => '\d+', + 'bar' => '\d+' + ], + $registry->all() + ); } } diff --git a/tests/Fixtures/TestRouterBootloader.php b/tests/Fixtures/TestRouterBootloader.php deleted file mode 100644 index 4411260..0000000 --- a/tests/Fixtures/TestRouterBootloader.php +++ /dev/null @@ -1,33 +0,0 @@ - fn(Container $container) => new LoaderRegistry([ - new PhpFileLoader($container, $container), - new TestLoader(), - ]), - ]; - } -} diff --git a/tests/GroupTest.php b/tests/GroupTest.php index 970f9fd..562a146 100644 --- a/tests/GroupTest.php +++ b/tests/GroupTest.php @@ -41,12 +41,12 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/test/id/900'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('900', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('900', (string)$response->getBody()); } public function testRouteOther(): void diff --git a/tests/HostsTest.php b/tests/HostsTest.php index ef05caf..bbdc302 100644 --- a/tests/HostsTest.php +++ b/tests/HostsTest.php @@ -33,14 +33,18 @@ public function testRoute(): void new Action(TestController::class, 'test') )); - self::assertNotNull($r = $router->handle(new ServerRequest('GET', 'http://domain.com/'))); + $this->assertNotNull( + $r = $router->handle(new ServerRequest('GET', 'http://domain.com/')) + ); - self::assertSame(200, $r->getStatusCode()); - self::assertSame('hello world', (string)$r->getBody()); + $this->assertSame(200, $r->getStatusCode()); + $this->assertSame('hello world', (string)$r->getBody()); - self::assertNotNull($r = $router->handle(new ServerRequest('GET', 'https://domain.com/'))); + $this->assertNotNull( + $r = $router->handle(new ServerRequest('GET', 'https://domain.com/')) + ); - self::assertSame(200, $r->getStatusCode()); - self::assertSame('hello world', (string)$r->getBody()); + $this->assertSame(200, $r->getStatusCode()); + $this->assertSame('hello world', (string)$r->getBody()); } } diff --git a/tests/Loader/Configurator/RouteConfiguratorTest.php b/tests/Loader/Configurator/RouteConfiguratorTest.php index af4a77e..58b46c6 100644 --- a/tests/Loader/Configurator/RouteConfiguratorTest.php +++ b/tests/Loader/Configurator/RouteConfiguratorTest.php @@ -27,7 +27,7 @@ public function testDestructException(): void $routes = new RouteCollection(); $configurator = new RouteConfigurator('test', '/', $routes); - self::assertCount(0, $routes); + $this->assertCount(0, $routes); $this->expectException(TargetException::class); unset($configurator); @@ -38,13 +38,13 @@ public function testDestruct(): void $routes = new RouteCollection(); $configurator = new RouteConfigurator('test', '/', $routes); - self::assertCount(0, $routes); + $this->assertCount(0, $routes); $configurator->controller('Controller'); unset($configurator); - self::assertCount(1, $routes); + $this->assertCount(1, $routes); } public function testController(): void @@ -52,7 +52,7 @@ public function testController(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('SomeController'); - self::assertInstanceOf(Controller::class, $configurator->target); + $this->assertInstanceOf(Controller::class, $configurator->target); } public function testNamespaced(): void @@ -60,7 +60,7 @@ public function testNamespaced(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->namespaced('App\\Controller'); - self::assertInstanceOf(Namespaced::class, $configurator->target); + $this->assertInstanceOf(Namespaced::class, $configurator->target); } public function testGroupControllers(): void @@ -68,7 +68,7 @@ public function testGroupControllers(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->groupControllers(['Controller']); - self::assertInstanceOf(Group::class, $configurator->target); + $this->assertInstanceOf(Group::class, $configurator->target); } public function testAction(): void @@ -76,7 +76,7 @@ public function testAction(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->action('Controller', 'action'); - self::assertInstanceOf(Action::class, $configurator->target); + $this->assertInstanceOf(Action::class, $configurator->target); } public function testCallable(): void @@ -84,7 +84,7 @@ public function testCallable(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->callable(fn () => null); - self::assertInstanceOf(\Closure::class, $configurator->target); + $this->assertInstanceOf(\Closure::class, $configurator->target); } public function testHandler(): void @@ -103,7 +103,7 @@ protected function resolveAction(array $matches): ?string } }); - self::assertInstanceOf(AbstractTarget::class, $configurator->target); + $this->assertInstanceOf(AbstractTarget::class, $configurator->target); } public function testDefaults(): void @@ -111,7 +111,7 @@ public function testDefaults(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->defaults(['some', 'array']); - self::assertSame(['some', 'array'], $configurator->defaults); + $this->assertSame(['some', 'array'], $configurator->defaults); } public function testGroup(): void @@ -119,7 +119,7 @@ public function testGroup(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->group('api'); - self::assertSame('api', $configurator->group); + $this->assertSame('api', $configurator->group); } public function testPrefix(): void @@ -127,7 +127,7 @@ public function testPrefix(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->prefix('admin'); - self::assertSame('admin', $configurator->prefix); + $this->assertSame('admin', $configurator->prefix); } public function testCore(): void @@ -135,18 +135,18 @@ public function testCore(): void $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->core(new Core(new Container())); - self::assertInstanceOf(Core::class, $configurator->core); + $this->assertInstanceOf(Core::class, $configurator->core); } public function testMiddleware(): void { $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->middleware('class-string'); - self::assertSame(['class-string'], $configurator->middleware); + $this->assertSame(['class-string'], $configurator->middleware); $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->middleware(['class-string', 'other-class-string']); - self::assertSame(['class-string', 'other-class-string'], $configurator->middleware); + $this->assertSame(['class-string', 'other-class-string'], $configurator->middleware); $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $testMiddleware = new class () implements MiddlewareInterface @@ -156,17 +156,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface } }; $configurator->controller('Controller')->middleware($testMiddleware); - self::assertSame([$testMiddleware], $configurator->middleware); + $this->assertSame([$testMiddleware], $configurator->middleware); } public function testMethods(): void { $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->methods('GET'); - self::assertSame(['GET'], $configurator->methods); + $this->assertSame(['GET'], $configurator->methods); $configurator = new RouteConfigurator('test', '/', new RouteCollection()); $configurator->controller('Controller')->methods(['GET', 'POST']); - self::assertSame(['GET', 'POST'], $configurator->methods); + $this->assertSame(['GET', 'POST'], $configurator->methods); } } diff --git a/tests/Loader/Configurator/RoutingConfiguratorTest.php b/tests/Loader/Configurator/RoutingConfiguratorTest.php index 6542a68..3dc094f 100644 --- a/tests/Loader/Configurator/RoutingConfiguratorTest.php +++ b/tests/Loader/Configurator/RoutingConfiguratorTest.php @@ -13,65 +13,65 @@ final class RoutingConfiguratorTest extends BaseTestCase { public function testImportWithoutConcreteLoader(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertCount(0, $routes->getCollection()); + $this->assertCount(0, $routes->getCollection()); $routes->import(\dirname(__DIR__, 2) . '/Fixtures/file.php'); - self::assertCount(3, $routes->getCollection()); + $this->assertCount(3, $routes->getCollection()); } public function testImportWithLoader(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertCount(0, $routes->getCollection()); + $this->assertCount(0, $routes->getCollection()); $routes->import(\dirname(__DIR__, 2) . '/Fixtures/file.php', 'php'); - self::assertCount(3, $routes->getCollection()); + $this->assertCount(3, $routes->getCollection()); } public function testImportWithWrongLoader(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertCount(0, $routes->getCollection()); + $this->assertCount(0, $routes->getCollection()); $routes->import(\dirname(__DIR__, 2) . '/Fixtures/file.php', 'yaml'); - self::assertCount(0, $routes->getCollection()); + $this->assertCount(0, $routes->getCollection()); } public function testGetCollection(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertInstanceOf(RouteCollection::class, $routes->getCollection()); + $this->assertInstanceOf(RouteCollection::class, $routes->getCollection()); } public function testDefault(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertNull($routes->getDefault()); + $this->assertNull($routes->getDefault()); $routes->default('/')->callable(static fn () => null); - self::assertInstanceOf(RouteConfigurator::class, $routes->getDefault()); + $this->assertInstanceOf(RouteConfigurator::class, $routes->getDefault()); } public function testAdd(): void { - $routes = $this->getContainer()->get(RoutingConfigurator::class); + $routes = $this->container->get(RoutingConfigurator::class); - self::assertCount(0, $routes->getCollection()); + $this->assertCount(0, $routes->getCollection()); $route = $routes->add('test', '/')->callable(static fn () => null); - self::assertInstanceOf(RouteConfigurator::class, $route); + $this->assertInstanceOf(RouteConfigurator::class, $route); // important. For destruct unset($route); - self::assertCount(1, $routes->getCollection()); + $this->assertCount(1, $routes->getCollection()); } } diff --git a/tests/Loader/DelegatingLoaderTest.php b/tests/Loader/DelegatingLoaderTest.php index 2a649d1..13c954d 100644 --- a/tests/Loader/DelegatingLoaderTest.php +++ b/tests/Loader/DelegatingLoaderTest.php @@ -20,33 +20,33 @@ public function testLoad(): void new TestLoader() ])); - self::assertInstanceOf(RouteCollection::class, $loader->load('file.yaml', 'yaml')); + $this->assertInstanceOf(RouteCollection::class, $loader->load('file.yaml', 'yaml')); } public function testSupports(): void { $loader = new DelegatingLoader(new LoaderRegistry()); - self::assertFalse($loader->supports('file.php')); - self::assertFalse($loader->supports('file.php', 'php')); + $this->assertFalse($loader->supports('file.php')); + $this->assertFalse($loader->supports('file.php', 'php')); $container = new Container(); $loader = new DelegatingLoader(new LoaderRegistry([new PhpFileLoader($container, $container)])); - self::assertTrue($loader->supports('file.php')); - self::assertTrue($loader->supports('file.php', 'php')); - self::assertFalse($loader->supports('file.php', 'yaml')); - self::assertFalse($loader->supports('file.yaml')); - self::assertFalse($loader->supports('file.yaml', 'yaml')); + $this->assertTrue($loader->supports('file.php')); + $this->assertTrue($loader->supports('file.php', 'php')); + $this->assertFalse($loader->supports('file.php', 'yaml')); + $this->assertFalse($loader->supports('file.yaml')); + $this->assertFalse($loader->supports('file.yaml', 'yaml')); $loader = new DelegatingLoader(new LoaderRegistry([ new PhpFileLoader($container, $container), new TestLoader() ])); - self::assertTrue($loader->supports('file.php')); - self::assertTrue($loader->supports('file.php', 'php')); - self::assertFalse($loader->supports('file.yaml')); - self::assertTrue($loader->supports('file.yaml', 'yaml')); - self::assertFalse($loader->supports('file.yaml', 'php')); + $this->assertTrue($loader->supports('file.php')); + $this->assertTrue($loader->supports('file.php', 'php')); + $this->assertFalse($loader->supports('file.yaml')); + $this->assertTrue($loader->supports('file.yaml', 'yaml')); + $this->assertFalse($loader->supports('file.yaml', 'php')); } } diff --git a/tests/Loader/LoaderRegistryTest.php b/tests/Loader/LoaderRegistryTest.php index 3e1385c..ea0b786 100644 --- a/tests/Loader/LoaderRegistryTest.php +++ b/tests/Loader/LoaderRegistryTest.php @@ -20,12 +20,12 @@ public function testResolve(): void new TestLoader() ]); - self::assertInstanceOf(PhpFileLoader::class, $registry->resolve('test/file.php')); - self::assertInstanceOf(PhpFileLoader::class, $registry->resolve('test/file.php', 'php')); - self::assertFalse($registry->resolve('test/file.php', 'txt')); + $this->assertInstanceOf(PhpFileLoader::class, $registry->resolve('test/file.php')); + $this->assertInstanceOf(PhpFileLoader::class, $registry->resolve('test/file.php', 'php')); + $this->assertFalse($registry->resolve('test/file.php', 'txt')); - self::assertInstanceOf(TestLoader::class, $registry->resolve('test/file.yaml', 'yaml')); - self::assertFalse($registry->resolve('test/file.yaml', 'php')); + $this->assertInstanceOf(TestLoader::class, $registry->resolve('test/file.yaml', 'yaml')); + $this->assertFalse($registry->resolve('test/file.yaml', 'php')); } public function testAddAndGetLoaders(): void @@ -35,12 +35,12 @@ public function testAddAndGetLoaders(): void $php = new PhpFileLoader($container, $container); $yaml = new TestLoader(); - self::assertSame([], $registry->getLoaders()); + $this->assertSame([], $registry->getLoaders()); $registry->addLoader($php); - self::assertSame([$php], $registry->getLoaders()); + $this->assertSame([$php], $registry->getLoaders()); $registry->addLoader($yaml); - self::assertSame([$php, $yaml], $registry->getLoaders()); + $this->assertSame([$php, $yaml], $registry->getLoaders()); } } diff --git a/tests/Loader/PhpFileLoaderTest.php b/tests/Loader/PhpFileLoaderTest.php index 80ae038..2f65ea4 100644 --- a/tests/Loader/PhpFileLoaderTest.php +++ b/tests/Loader/PhpFileLoaderTest.php @@ -30,8 +30,8 @@ public function testLoad(): void $loader = new PhpFileLoader($this->container, $this->container); $routes = $loader->load(\dirname(__DIR__) . '/Fixtures/file.php'); - self::assertInstanceOf(RouteCollection::class, $routes); - self::assertCount(3, $routes); + $this->assertInstanceOf(RouteCollection::class, $routes); + $this->assertCount(3, $routes); $this->expectException(LoaderLoadException::class); $loader->load(\dirname(__DIR__) . '/Fixtures/unknown.php'); @@ -41,11 +41,11 @@ public function testSupports(): void { $loader = new PhpFileLoader($this->container, $this->container); - self::assertTrue($loader->supports('file.php')); - self::assertTrue($loader->supports('file.php', 'php')); + $this->assertTrue($loader->supports('file.php')); + $this->assertTrue($loader->supports('file.php', 'php')); - self::assertFalse($loader->supports('file.php', 'txt')); - self::assertFalse($loader->supports('file.txt')); - self::assertFalse($loader->supports('file.txt', 'txt')); + $this->assertFalse($loader->supports('file.php', 'txt')); + $this->assertFalse($loader->supports('file.txt')); + $this->assertFalse($loader->supports('file.txt', 'txt')); } } diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index cd6f161..aa114d2 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -6,7 +6,6 @@ use Nyholm\Psr7\ServerRequest; use Nyholm\Psr7\Uri; -use Psr\Container\NotFoundExceptionInterface; use Spiral\Router\Exception\RouteException; use Spiral\Router\Route; use Spiral\Router\Target\Group; @@ -15,10 +14,8 @@ use Spiral\Tests\Router\Fixtures\TestController; use Spiral\Tests\Router\Stub\HeaderMiddleware; -class MiddlewareTest extends BaseTestingCase +class MiddlewareTest extends BaseTestCase { - use RouterFactoryTrait; - public function testRoute(): void { $router = $this->makeRouter(); @@ -31,17 +28,17 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*', $response->getHeaderLine('Header')); $r = $router->getRoute('group')->withMiddleware(HeaderMiddleware::class); $r = $r->match(new ServerRequest('GET', new Uri('/test'))); $response = $r->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*, Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); } public function testRouteRuntime(): void @@ -56,9 +53,9 @@ public function testRouteRuntime(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*', $response->getHeaderLine('Header')); } public function testRouteArray(): void @@ -73,40 +70,52 @@ public function testRouteArray(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*, Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*, Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); } public function testInvalid(): void { + $this->expectException(RouteException::class); + $router = $this->makeRouter(); - $this->expectException(\Throwable::class); $router->setRoute( 'group', (new Route('/[/[/]]', new Group([ 'test' => TestController::class, ])))->withMiddleware($this) ); + + $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); } public function testInvalid2(): void { + $this->expectException(RouteException::class); + $router = $this->makeRouter(); - $this->expectException(\Throwable::class); $router->setRoute( 'group', (new Route('/[/[/]]', new Group([ 'test' => TestController::class, ])))->withMiddleware([[]]) ); + + $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); } public function testPipelineException(): void @@ -120,23 +129,23 @@ public function testPipelineException(): void $r = $r->match(new ServerRequest('GET', new Uri('/test'))); $response = $r->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); - self::assertSame('Value*, Value*', $response->getHeaderLine('Header')); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); + $this->assertSame('Value*, Value*', $response->getHeaderLine('Header')); } - public function testUndefinedMiddleware(): void + public function testPipelineExceptionMiddleware(): void { + $this->expectException(RouteException::class); + $r = (new Route('/[/[/]]', new Group([ 'test' => TestController::class, ])))->withMiddleware([new HeaderMiddleware(), 'other']); $r = $r->withUriHandler(new UriHandler(new UriFactory())); - $r = $r->withContainer($this->getContainer()); + $r = $r->withContainer($this->container); $r = $r->match(new ServerRequest('GET', new Uri('/test'))); - - $this->expectException(NotFoundExceptionInterface::class); $r->handle(new ServerRequest('GET', new Uri('/test'))); } } diff --git a/tests/MultipleActionsTest.php b/tests/MultipleActionsTest.php index 58037d0..cc3f324 100644 --- a/tests/MultipleActionsTest.php +++ b/tests/MultipleActionsTest.php @@ -35,12 +35,12 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/id/900'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('900', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('900', (string)$response->getBody()); } public function testUriGeneration(): void @@ -52,9 +52,9 @@ public function testUriGeneration(): void ); $uri = $router->uri('action/test'); - self::assertSame('/test', $uri->getPath()); + $this->assertSame('/test', $uri->getPath()); $uri = $router->uri('action/id', ['id' => 100]); - self::assertSame('/id/100', $uri->getPath()); + $this->assertSame('/id/100', $uri->getPath()); } } diff --git a/tests/NamespacedTest.php b/tests/NamespacedTest.php index cc74685..9583891 100644 --- a/tests/NamespacedTest.php +++ b/tests/NamespacedTest.php @@ -41,16 +41,16 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/test/id/900'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('900', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('900', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/other/action'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('action!', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('action!', (string)$response->getBody()); } public function testBypass(): void @@ -59,7 +59,7 @@ public function testBypass(): void $n = new Namespaced('Spiral\Tests\Router\Fixtures'); - $n->getHandler($this->getContainer(), [ + $n->getHandler($this->container, [ 'controller' => 'secret/controller', 'action' => null, ]); diff --git a/tests/PatternsTests.php b/tests/PatternsTests.php index 2567127..33cdb2f 100644 --- a/tests/PatternsTests.php +++ b/tests/PatternsTests.php @@ -28,7 +28,7 @@ public function testDigitWithZeroValue(): void $match = $route->match(new ServerRequest('GET', new Uri('http://site.com/statistics/set/10/285/0'))); - self::assertSame([ + $this->assertSame([ 'moduleType' => '10', 'moduleId' => '285', 'type' => '0', @@ -48,7 +48,7 @@ public function testIntPatternWithValidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/1')) ); - self::assertSame([ + $this->assertSame([ 'int' => '1', ], $match->getMatches()); } @@ -66,7 +66,7 @@ public function testIntPatternWithInvalidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/1b')) ); - self::assertNull($match); + $this->assertNull($match); } public function testIntegerPatternWithValidValue(): void @@ -82,7 +82,7 @@ public function testIntegerPatternWithValidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/1')) ); - self::assertSame([ + $this->assertSame([ 'integer' => '1', ], $match->getMatches()); } @@ -100,7 +100,7 @@ public function testIntegerPatternWithInvalidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/1b')) ); - self::assertNull($match); + $this->assertNull($match); } public function testUuidPatternWithValidValue(): void @@ -116,7 +116,7 @@ public function testUuidPatternWithValidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/34f7b660-7ad0-11ed-a1eb-0242ac120002')) ); - self::assertSame([ + $this->assertSame([ 'uuid' => '34f7b660-7ad0-11ed-a1eb-0242ac120002', ], $match->getMatches()); } @@ -134,7 +134,7 @@ public function testUuidPatternWithInvalidValue(): void new ServerRequest('GET', new Uri('http://site.com/users/34f7b660-7ad0')) ); - self::assertNull($match); + $this->assertNull($match); } public function testCustomPattern(): void @@ -162,7 +162,7 @@ public function testCustomPattern(): void new ServerRequest('GET', new Uri('http://site.com/users/34f7b660-7ad0-11ed-a1eb-0242ac222222')) ); - self::assertSame([ + $this->assertSame([ 'uuid' => '34f7b660-7ad0-11ed-a1eb-0242ac222222', ], $match->getMatches()); } @@ -202,12 +202,12 @@ public function testCustomStringablePattern(): void new ServerRequest('GET', new Uri('http://site.com/users/baz')) ); - self::assertSame([ + $this->assertSame([ 'name' => 'foo', ], $match->getMatches()); - self::assertSame([ + $this->assertSame([ 'name' => 'bar', ], $match1->getMatches()); - self::assertNull($match2); + $this->assertNull($match2); } } diff --git a/tests/PipelineFactoryTest.php b/tests/PipelineFactoryTest.php index 4b5f793..1725da5 100644 --- a/tests/PipelineFactoryTest.php +++ b/tests/PipelineFactoryTest.php @@ -43,7 +43,10 @@ public function testCreatesFromArrayWithPipeline(): void scope: $this->createMock(ScopeInterface::class), ); - self::assertSame($newPipeline, $this->pipeline->createWithMiddleware([$newPipeline])); + $this->assertSame( + $newPipeline, + $this->pipeline->createWithMiddleware([$newPipeline]) + ); } public function testCreates(): void @@ -72,14 +75,14 @@ public function testCreates(): void ->with('foo') ->willReturn($middleware4 = $this->createMock(MiddlewareInterface::class)); - self::assertSame($p, $this->pipeline->createWithMiddleware([ + $this->assertSame($p, $this->pipeline->createWithMiddleware([ 'foo', $middleware1 = $this->createMock(MiddlewareInterface::class), $middleware2 = $this->createMock(MiddlewareInterface::class), new Autowire('bar'), ])); - $handle = fn(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface => $handler->handle($request); + $handle = fn(ServerRequestInterface $request, RequestHandlerInterface $handler) => $handler->handle($request); $middleware1->expects($this->once())->method('process')->willReturnCallback($handle); $middleware2->expects($this->once())->method('process')->willReturnCallback($handle); diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php index 62352f7..e6ebb81 100644 --- a/tests/RegistryTest.php +++ b/tests/RegistryTest.php @@ -14,11 +14,11 @@ final class RegistryTest extends BaseTestCase { public function testSameGroup(): void { - $registry = new GroupRegistry($this->getContainer()); - $router = new Router('/', new UriHandler(new Psr17Factory()), $this->getContainer()); - $this->getContainer()->bind(RouterInterface::class, $router); + $registry = new GroupRegistry($this->container); + $router = new Router('/', new UriHandler(new Psr17Factory()), $this->container); + $this->container->bind(RouterInterface::class, $router); $group = $registry->getGroup('default'); - self::assertSame($group, $registry->getGroup('default')); + $this->assertSame($group, $registry->getGroup('default')); } } diff --git a/tests/RouteGroupTest.php b/tests/RouteGroupTest.php index debf650..c4bb000 100644 --- a/tests/RouteGroupTest.php +++ b/tests/RouteGroupTest.php @@ -40,12 +40,12 @@ public function testCoreString(): void $t = $this->getProperty($this->router->getRoute('name'), 'target'); - self::assertInstanceOf(Action::class, $t); + $this->assertInstanceOf(Action::class, $t); - self::assertSame('controller', $this->getProperty($t, 'controller')); - self::assertSame('method', $this->getProperty($t, 'action')); + $this->assertSame('controller', $this->getProperty($t, 'controller')); + $this->assertSame('method', $this->getProperty($t, 'action')); - self::assertInstanceOf(RoutesTestCore::class, $this->getActionProperty($t, 'pipeline')); + $this->assertInstanceOf(RoutesTestCore::class, $this->getActionProperty($t, 'pipeline')); } public function testCoreObject(): void @@ -58,12 +58,12 @@ public function testCoreObject(): void $t = $this->getProperty($this->router->getRoute('name'), 'target'); - self::assertInstanceOf(Action::class, $t); + $this->assertInstanceOf(Action::class, $t); - self::assertSame('controller', $this->getProperty($t, 'controller')); - self::assertSame('method', $this->getProperty($t, 'action')); + $this->assertSame('controller', $this->getProperty($t, 'controller')); + $this->assertSame('method', $this->getProperty($t, 'action')); - self::assertInstanceOf(RoutesTestCore::class, $this->getActionProperty($t, 'pipeline')); + $this->assertInstanceOf(RoutesTestCore::class, $this->getActionProperty($t, 'pipeline')); } public function testGroupHasRoute(): void @@ -73,8 +73,8 @@ public function testGroupHasRoute(): void $group->addRoute('foo', new Route('/', new Action('controller', 'method'))); $group->register($this->router, $this->container); - self::assertTrue($group->hasRoute('foo')); - self::assertFalse($group->hasRoute('bar')); + $this->assertTrue($group->hasRoute('foo')); + $this->assertFalse($group->hasRoute('bar')); } #[DataProvider('middlewaresDataProvider')] @@ -92,9 +92,8 @@ public function testMiddleware(mixed $middleware): void $p = $this->getProperty($r, 'pipeline'); $m = $this->getProperty($p, 'middleware'); - self::assertCount(1, $m); - // Because of the pipeline is lazy - self::assertSame($middleware, $m[0]); + $this->assertCount(1, $m); + $this->assertInstanceOf(TestMiddleware::class, $m[0]); } public function testRouteWithMiddlewareAddGroupMiddleware(): void @@ -111,11 +110,10 @@ public function testRouteWithMiddlewareAddGroupMiddleware(): void $p = $this->getProperty($r, 'pipeline'); $m = $this->getProperty($p, 'middleware'); - self::assertCount(2, $m); + $this->assertCount(2, $m); - // Because of the pipeline is lazy - self::assertSame(TestMiddleware::class, $m[1]); - self::assertSame(AnotherMiddleware::class, $m[0]); + $this->assertInstanceOf(TestMiddleware::class, $m[1]); + $this->assertInstanceOf(AnotherMiddleware::class, $m[0]); } public function testWithoutNamePrefix(): void @@ -124,7 +122,7 @@ public function testWithoutNamePrefix(): void $group->addRoute('name', new Route('/', new Action('controller', 'method'))); $group->register($this->router, $this->container); - self::assertTrue($group->hasRoute('name')); + $this->assertTrue($group->hasRoute('name')); } public function testWithNamePrefix(): void @@ -134,8 +132,8 @@ public function testWithNamePrefix(): void $group->addRoute('name', new Route('/', new Action('controller', 'method'))); $group->register($this->router, $this->container); - self::assertTrue($group->hasRoute('admin.name')); - self::assertFalse($group->hasRoute('name')); + $this->assertTrue($group->hasRoute('admin.name')); + $this->assertFalse($group->hasRoute('name')); } #[DataProvider('routePrefixDataProvider')] @@ -148,9 +146,11 @@ public function testWithPrefix(string $prefix, string $pattern): void $group->register($this->router, $this->container); $route = $this->router->getRoute('name'); - self::assertNotNull($route->match(new ServerRequest('GET', '/api/blog'))); + $this->assertNotNull( + $route->match(new ServerRequest('GET', '/api/blog')) + ); - self::assertSame('/api/blog', (string) $route->uri()); + $this->assertSame('/api/blog', (string) $route->uri()); } public static function routePrefixDataProvider(): iterable diff --git a/tests/RouteTest.php b/tests/RouteTest.php index 85a0f1d..fe8e8eb 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -19,7 +19,7 @@ public function testEmptyPrefix(): void $route = new Route('/action', Call::class); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame('', $route->getUriHandler()->getPrefix()); + $this->assertSame('', $route->getUriHandler()->getPrefix()); } #[DataProvider('prefixesDataProvider')] @@ -28,7 +28,7 @@ public function testPrefix(string $prefix, string $expected): void $route = new Route('/action', Call::class); $route = $route->withUriHandler((new UriHandler(new UriFactory()))->withPrefix($prefix)); - self::assertSame($expected, $route->getUriHandler()->getPrefix()); + $this->assertSame($expected, $route->getUriHandler()->getPrefix()); } public function testContainerException(): void @@ -50,9 +50,8 @@ public function testWithMiddleware(mixed $middleware): void $p = $this->getProperty($route, 'pipeline'); $m = $this->getProperty($p, 'middleware'); - self::assertCount(1, $m); - // Because of the pipeline is lazy - self::assertSame($middleware, $m[0]); + $this->assertCount(1, $m); + $this->assertInstanceOf(TestMiddleware::class, $m[0]); } public static function prefixesDataProvider(): \Traversable diff --git a/tests/RouterFactoryTrait.php b/tests/RouterFactoryTrait.php deleted file mode 100644 index 01f2991..0000000 --- a/tests/RouterFactoryTrait.php +++ /dev/null @@ -1,34 +0,0 @@ -getContainer(); - return new Router( - $basePath, - new UriHandler( - new UriFactory(), - new Slugify(), - ), - $container, - $dispatcher, - new NullTracer($container), - ); - } -} diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 6d4fa5c..01ac370 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -24,7 +24,7 @@ public function testGetRoutes(): void $router = $this->makeRouter(); $router->setRoute('name', new Route('/', Call::class)); - self::assertCount(1, $router->getRoutes()); + $this->assertCount(1, $router->getRoutes()); } public function testDefault(): void @@ -34,7 +34,7 @@ public function testDefault(): void $router->setRoute('name', new Route('/', Call::class)); $router->setDefault(new Route('/', Call::class)); - self::assertCount(2, $router->getRoutes()); + $this->assertCount(2, $router->getRoutes()); } public function testCastError(): void @@ -48,7 +48,7 @@ public function testCastError(): void public function testEventsShouldBeDispatched(): void { $request = new ServerRequest('GET', '/foo'); - $route = (new Route('/foo', Call::class))->withContainer($this->getContainer()); + $route = (new Route('/foo', Call::class))->withContainer($this->container); $dispatcher = $this->createMock(EventDispatcherInterface::class); $dispatcher @@ -88,10 +88,10 @@ public function testImportWithHost(): void $configurator->add('foo', '///register')->callable(fn () => null); $router->import($configurator); - $this->getContainer()->get(GroupRegistry::class)->registerRoutes($router); + $this->container->get(GroupRegistry::class)->registerRoutes($router); $uri = (string) $router->uri('foo', ['host' => 'some']); - self::assertSame('some/register', $uri); - self::assertFalse(\str_contains('https://host.com', $uri)); + $this->assertSame('some/register', $uri); + $this->assertFalse(\str_contains('https://host.com', $uri)); } } diff --git a/tests/SingleActionTest.php b/tests/SingleActionTest.php index 756ba96..278919c 100644 --- a/tests/SingleActionTest.php +++ b/tests/SingleActionTest.php @@ -36,12 +36,12 @@ public function testRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); } public function testVerbRoute(): void @@ -66,8 +66,8 @@ public function testVerbRouteValid(): void ); $response = $router->handle(new ServerRequest('POST', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('hello world', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('hello world', (string)$response->getBody()); } public function testEchoed(): void @@ -79,8 +79,8 @@ public function testEchoed(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('echoed', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('echoed', (string)$response->getBody()); } public function testAutoFill(): void @@ -92,8 +92,8 @@ public function testAutoFill(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/echo'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('echoed', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('echoed', (string)$response->getBody()); $e = null; try { @@ -101,7 +101,7 @@ public function testAutoFill(): void } catch (UndefinedRouteException $e) { } - self::assertNotNull($e, 'Autofill not fired'); + $this->assertNotNull($e, 'Autofill not fired'); } public function testVerbException(): void @@ -124,8 +124,8 @@ public function testParametrizedActionRoute(): void ); $response = $router->handle(new ServerRequest('GET', new Uri('/test/100'))); - self::assertSame(200, $response->getStatusCode()); - self::assertSame('100', (string)$response->getBody()); + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('100', (string)$response->getBody()); } public function testParametrizedActionRouteNotFound(): void @@ -150,10 +150,10 @@ public function testUriGeneration(): void ); $uri = $router->uri('action'); - self::assertSame('/test', $uri->getPath()); + $this->assertSame('/test', $uri->getPath()); $uri = $router->uri('action', ['id' => 100]); - self::assertSame('/test/100', $uri->getPath()); + $this->assertSame('/test/100', $uri->getPath()); } public function testWrongActionRoute(): void diff --git a/tests/SubdomainTest.php b/tests/SubdomainTest.php index 9fa4694..637aee6 100644 --- a/tests/SubdomainTest.php +++ b/tests/SubdomainTest.php @@ -24,10 +24,10 @@ public function testSubDomainWithoutAction(): void $route = $route->withUriHandler(new UriHandler(new UriFactory())); $match = $route->match(new ServerRequest('GET', new Uri('http://site.com/foo'))); - self::assertSame(['sub' => 'subdomain'], $match->getMatches()); + $this->assertSame(['sub' => 'subdomain'], $match->getMatches()); $match = $route->match(new ServerRequest('GET', new Uri('http://bar.site.com/foo'))); - self::assertSame(['sub' => 'bar'], $match->getMatches()); + $this->assertSame(['sub' => 'bar'], $match->getMatches()); } public function testSubDomainWithAction(): void @@ -41,15 +41,15 @@ public function testSubDomainWithAction(): void $route = $route->withUriHandler(new UriHandler(new UriFactory())); $match = $route->match(new ServerRequest('GET', new Uri('http://site.com/foo/bar'))); - self::assertSame(['sub' => 'subdomain', 'action' => 'bar'], $match->getMatches()); + $this->assertSame(['sub' => 'subdomain', 'action' => 'bar'], $match->getMatches()); $match = $route->match(new ServerRequest('GET', new Uri('http://site.com/foo'))); - self::assertSame(['sub' => 'subdomain', 'action' => null], $match->getMatches()); + $this->assertSame(['sub' => 'subdomain', 'action' => null], $match->getMatches()); $match = $route->match(new ServerRequest('GET', new Uri('http://bar.site.com/foo'))); - self::assertSame(['sub' => 'bar', 'action' => null], $match->getMatches()); + $this->assertSame(['sub' => 'bar', 'action' => null], $match->getMatches()); $match = $route->match(new ServerRequest('GET', new Uri('http://bar.site.com/foo/bar'))); - self::assertSame(['sub' => 'bar', 'action' => 'bar'], $match->getMatches()); + $this->assertSame(['sub' => 'bar', 'action' => 'bar'], $match->getMatches()); } } diff --git a/tests/Targets/ActionTargetTest.php b/tests/Targets/ActionTargetTest.php index 89066cd..ece4c7f 100644 --- a/tests/Targets/ActionTargetTest.php +++ b/tests/Targets/ActionTargetTest.php @@ -22,7 +22,7 @@ public function testDefaultAction(): void $route = new Route('/home', new Action(TestController::class, 'test')); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame(['action' => 'test'], $route->getDefaults()); + $this->assertSame(['action' => 'test'], $route->getDefaults()); } public function testConstrains(): void @@ -30,12 +30,12 @@ public function testConstrains(): void $route = new Route('/home', new Action(TestController::class, 'test')); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertEquals(['action' => new Autofill('test')], $route->getUriHandler()->getConstrains()); + $this->assertEquals(['action' => new Autofill('test')], $route->getUriHandler()->getConstrains()); $route = new Route('/', new Action(TestController::class, ['test', 'other'])); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame(['action' => ['test', 'other']], $route->getUriHandler()->getConstrains()); + $this->assertSame(['action' => ['test', 'other']], $route->getUriHandler()->getConstrains()); } public function testConstrainedAction(): void @@ -58,25 +58,35 @@ public function testMatch(): void $route = $route->withDefaults(['action' => 'test']); - self::assertNull($route->match(new ServerRequest('GET', ''))); - self::assertNull($route->match(new ServerRequest('GET', new Uri('/test/something')))); - self::assertNull($route->match(new ServerRequest('GET', new Uri('/test/tester')))); + $this->assertNull($route->match(new ServerRequest('GET', ''))); + $this->assertNull($route->match(new ServerRequest('GET', new Uri('/test/something')))); + $this->assertNull($route->match(new ServerRequest('GET', new Uri('/test/tester')))); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test'))) + ); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/')))); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/'))) + ); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/test')))); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/test'))) + ); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/test/')))); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/test/'))) + ); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/other')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/other'))) + ); - self::assertSame(['action' => 'other'], $match->getMatches()); + $this->assertSame(['action' => 'other'], $match->getMatches()); } } diff --git a/tests/Targets/ControllerTargetTest.php b/tests/Targets/ControllerTargetTest.php index ff857b5..fefcd7b 100644 --- a/tests/Targets/ControllerTargetTest.php +++ b/tests/Targets/ControllerTargetTest.php @@ -20,7 +20,7 @@ public function testDefaultAction(): void $route = new Route('/home[/]', new Controller(TestController::class)); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame(['action' => null], $route->getDefaults()); + $this->assertSame(['action' => null], $route->getDefaults()); } public function testMatch(): void @@ -31,25 +31,35 @@ public function testMatch(): void ); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertNull($route->match(new ServerRequest('GET', ''))); - self::assertNotNull($route->match(new ServerRequest('GET', new Uri('/test/something')))); - self::assertNotNull($route->match(new ServerRequest('GET', new Uri('/test/tester')))); + $this->assertNull($route->match(new ServerRequest('GET', ''))); + $this->assertNotNull($route->match(new ServerRequest('GET', new Uri('/test/something')))); + $this->assertNotNull($route->match(new ServerRequest('GET', new Uri('/test/tester')))); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test'))) + ); - self::assertSame(['action' => null], $match->getMatches()); + $this->assertSame(['action' => null], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/')))); - self::assertSame(['action' => null], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/'))) + ); + $this->assertSame(['action' => null], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/test')))); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/test'))) + ); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/test/')))); - self::assertSame(['action' => 'test'], $match->getMatches()); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/test/'))) + ); + $this->assertSame(['action' => 'test'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/other')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/other'))) + ); - self::assertSame(['action' => 'other'], $match->getMatches()); + $this->assertSame(['action' => 'other'], $match->getMatches()); } } diff --git a/tests/Targets/GroupTargetTest.php b/tests/Targets/GroupTargetTest.php index d25c073..a4f8291 100644 --- a/tests/Targets/GroupTargetTest.php +++ b/tests/Targets/GroupTargetTest.php @@ -21,7 +21,7 @@ public function testDefaultAction(): void $route = new Route('//', new Group(['test' => TestController::class])); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame(['controller' => null, 'action' => null], $route->getDefaults()); + $this->assertSame(['controller' => null, 'action' => null], $route->getDefaults()); } public function testConstrainedController(): void @@ -54,18 +54,26 @@ public function testMatch(): void $route = $route->withDefaults(['controller' => 'test']); - self::assertNull($route->match(new ServerRequest('GET', ''))); + $this->assertNull($route->match(new ServerRequest('GET', ''))); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test'))) + ); - self::assertSame(['controller' => 'test', 'action' => null], $match->getMatches()); + $this->assertSame(['controller' => 'test', 'action' => null], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/action/')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/action/'))) + ); - self::assertSame(['controller' => 'test', 'action' => 'action'], $match->getMatches()); + $this->assertSame(['controller' => 'test', 'action' => 'action'], $match->getMatches()); - self::assertNull($match = $route->match(new ServerRequest('GET', new Uri('/other/action/')))); + $this->assertNull( + $match = $route->match(new ServerRequest('GET', new Uri('/other/action/'))) + ); - self::assertNull($match = $route->match(new ServerRequest('GET', new Uri('/other')))); + $this->assertNull( + $match = $route->match(new ServerRequest('GET', new Uri('/other'))) + ); } } diff --git a/tests/Targets/NamespacedTargetTest.php b/tests/Targets/NamespacedTargetTest.php index 3810223..f5bed2b 100644 --- a/tests/Targets/NamespacedTargetTest.php +++ b/tests/Targets/NamespacedTargetTest.php @@ -21,7 +21,7 @@ public function testDefaultAction(): void $route = new Route('//', new Namespaced('Spiral\Router\Fixtures')); $route = $route->withUriHandler(new UriHandler(new UriFactory())); - self::assertSame(['controller' => null, 'action' => null], $route->getDefaults()); + $this->assertSame(['controller' => null, 'action' => null], $route->getDefaults()); } public function testConstrainedController(): void @@ -54,19 +54,25 @@ public function testMatch(): void $route = $route->withDefaults(['controller' => 'test']); - self::assertNull($route->match(new ServerRequest('GET', ''))); + $this->assertNull($route->match(new ServerRequest('GET', ''))); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test'))) + ); - self::assertSame(['controller' => 'test', 'action' => null], $match->getMatches()); + $this->assertSame(['controller' => 'test', 'action' => null], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/test/action/')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/test/action/'))) + ); - self::assertSame(['controller' => 'test', 'action' => 'action'], $match->getMatches()); + $this->assertSame(['controller' => 'test', 'action' => 'action'], $match->getMatches()); - self::assertNotNull($match = $route->match(new ServerRequest('GET', new Uri('/other/action/')))); + $this->assertNotNull( + $match = $route->match(new ServerRequest('GET', new Uri('/other/action/'))) + ); - self::assertSame(['controller' => 'other', 'action' => 'action'], $match->getMatches()); + $this->assertSame(['controller' => 'other', 'action' => 'action'], $match->getMatches()); } #[DataProvider('defaultProvider')] @@ -78,11 +84,11 @@ public function testDefaults(string $pattern, string $uri, array $defaults): voi $request = new ServerRequest('GET', new Uri($uri)); $match = $route->match($request); - self::assertNotNull($match); + $this->assertNotNull($match); $values = $match->getMatches(); - self::assertNotNull($values['controller']); - self::assertNotNull($values['action']); + $this->assertNotNull($values['controller']); + $this->assertNotNull($values['action']); } public static function defaultProvider(): \Traversable diff --git a/tests/UriTest.php b/tests/UriTest.php index 4a18493..2e3ded5 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -23,7 +23,7 @@ public function testCastRoute(): void ); $uri = $router->uri('group/test:test'); - self::assertSame('/test/test', $uri->getPath()); + $this->assertSame('/test/test', $uri->getPath()); } public function testQuery(): void @@ -37,8 +37,8 @@ public function testQuery(): void ); $uri = $router->uri('group/test:id', ['id' => 100, 'data' => 'hello']); - self::assertSame('/test/id/100', $uri->getPath()); - self::assertSame('data=hello', $uri->getQuery()); + $this->assertSame('/test/id/100', $uri->getPath()); + $this->assertSame('data=hello', $uri->getQuery()); } public function testDirect(): void @@ -52,7 +52,7 @@ public function testDirect(): void ); $uri = $router->getRoute('group')->uri(['test', 'id', 100]); - self::assertSame('/test/id/100', $uri->getPath()); + $this->assertSame('/test/id/100', $uri->getPath()); } public function testSlug(): void @@ -66,7 +66,7 @@ public function testSlug(): void ); $uri = $router->getRoute('group')->uri(['test', 'id', 100, 'Hello World']); - self::assertSame('/test/id/100-hello-world', $uri->getPath()); + $this->assertSame('/test/id/100-hello-world', $uri->getPath()); } public function testSlugDefault(): void @@ -79,7 +79,7 @@ public function testSlugDefault(): void ); $uri = $router->uri('test:id', ['id' => 100, 'title' => 'Hello World']); - self::assertSame('/test/id/100-hello-world', $uri->getPath()); + $this->assertSame('/test/id/100-hello-world', $uri->getPath()); } public function testSlugNoDefault(): void @@ -89,7 +89,7 @@ public function testSlugNoDefault(): void $router = $this->makeRouter(); $uri = $router->uri('test:id', ['id' => 100, 'title' => 'Hello World']); - self::assertSame('/test/id/100-hello-world', $uri->getPath()); + $this->assertSame('/test/id/100-hello-world', $uri->getPath()); } public function testObject(): void @@ -111,7 +111,7 @@ public function __toString() }, ]); - self::assertSame('/test/id/100-hello-world', $uri->getPath()); + $this->assertSame('/test/id/100-hello-world', $uri->getPath()); } #[DataProvider('provideSegmentInDifferentLanguages')] @@ -126,12 +126,11 @@ public function testCustomPathSegmentEncoder(string $segment, string $expected): ); $route = $router->getRoute('group'); - $uriHandler = $route->getUriHandler() - ->withPathSegmentEncoder(static fn(string $segment): string => \rawurlencode($segment)); + $uriHandler = $route->getUriHandler()->withPathSegmentEncoder(fn(string $segment) => \rawurlencode($segment)); $route = $route->withUriHandler($uriHandler); $uri = $route->uri(['controller' => 'test', 'action' => $segment]); - self::assertSame($expected, $uri->getPath()); + $this->assertSame($expected, $uri->getPath()); } public static function provideSegmentInDifferentLanguages(): iterable