Skip to content

Commit

Permalink
fix: Missing param to ServiceManager in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gashmob committed Dec 30, 2024
1 parent 8ab945f commit 17fb63b
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions tests/unit/Route/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@
use Archict\Router\Method;
use Archict\Router\RequestHandler;
use Archict\Router\ResponseFactory;
use CuyZ\Valinor\Mapper\TreeMapper;
use CuyZ\Valinor\MapperBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class RouteCollectionTest extends TestCase
{
private TreeMapper $mapper;

protected function setUp(): void
{
$this->mapper = (new MapperBuilder())->enableFlexibleCasting()->allowSuperfluousKeys()->allowPermissiveTypes()->mapper();
}

public function testItCanAddRouteWithRequestHandler(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(
Method::GET,
Expand All @@ -59,15 +68,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface // ph

public function testItCanAddRouteWithCallable(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
}

public function testItCanAddRouteWithClassname(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
$handler = new class implements RequestHandler {
public function handle(ServerRequestInterface $request): ResponseInterface // phpcs:ignore
{
Expand All @@ -79,7 +88,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface // ph

public function testItNotAcceptIfAddTwiceSameRoute(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -90,7 +99,7 @@ public function testItNotAcceptIfAddTwiceSameRoute(): void

public function testItAcceptSameRouteDifferentMethod(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -101,7 +110,7 @@ public function testItAcceptSameRouteDifferentMethod(): void

public function testItNotAcceptSameRouteWithMethodAll(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -112,7 +121,7 @@ public function testItNotAcceptSameRouteWithMethodAll(): void

public function testItNotAcceptSameRouteIfFirstIsMethodAll(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::ALL, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -123,7 +132,7 @@ public function testItNotAcceptSameRouteIfFirstIsMethodAll(): void

public function testItAcceptSeveralRoute(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, 'route1', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -137,7 +146,7 @@ public function testItAcceptSeveralRoute(): void

public function testItAcceptSameRouteWithDifferentGroup(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::assertTrue(
$collection->addRoute(Method::GET, '{group:\d+}', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()) // phpcs:ignore
);
Expand All @@ -148,22 +157,22 @@ public function testItAcceptSameRouteWithDifferentGroup(): void

public function testItThrowIfRouteNotFound(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::expectException(NotFoundException::class);
$collection->getMatchingRoute('', 'GET');
}

public function testItThrowIfMethodNotAllowed(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
$collection->addRoute(Method::GET, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()); // phpcs:ignore
self::expectException(MethodNotAllowedException::class);
$collection->getMatchingRoute('route', 'POST');
}

public function testItCanFindMatchingRouteSimple(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
$collection->addRoute(Method::ALL, 'route', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()); // phpcs:ignore
$route = $collection->getMatchingRoute('route', 'PATCH');

Expand All @@ -173,7 +182,7 @@ public function testItCanFindMatchingRouteSimple(): void

public function testItCanFindMatchingRouteWithGroup(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
$collection->addRoute(Method::GET, 'article/{id:\d+}', static fn(ServerRequestInterface $request) => ResponseFactory::build()->get()); // phpcs:ignore
$route = $collection->getMatchingRoute('article/5', 'GET');

Expand All @@ -183,28 +192,28 @@ public function testItCanFindMatchingRouteWithGroup(): void

public function testItCanAddMiddlewareWithCallable(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::expectNotToPerformAssertions();
$collection->addMiddleware(Method::GET, 'route', static fn(ServerRequestInterface $request) => $request);
}

public function testItCanAddMiddlewareWithMiddleware(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::expectNotToPerformAssertions();
$collection->addMiddleware(Method::GET, 'route', new IdentityMiddlewareStub());
}

public function testItCanAddMiddlewareWithClassname(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::expectNotToPerformAssertions();
$collection->addMiddleware(Method::GET, 'route', IdentityMiddlewareStub::class);
}

public function testItAcceptMultipleMiddlewareOnSameRoute(): void
{
$collection = new RouteCollection(new ServiceManager());
$collection = new RouteCollection(new ServiceManager($this->mapper));
self::expectNotToPerformAssertions();
$collection->addMiddleware(Method::GET, 'route', new IdentityMiddlewareStub());
$collection->addMiddleware(Method::GET, 'route', new IdentityMiddlewareStub());
Expand Down

0 comments on commit 17fb63b

Please sign in to comment.