diff --git a/composer.json b/composer.json index 666dad7..69e5ca6 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,7 @@ "cs": "phpcs --config-set php_version 7040 && phpcs", "csfix": "phpcs --config-set php_version 7040 && phpcbf", "psalm": "psalm", - "stan": "phpstan analyse --memory-limit=-1", + "stan": "phpstan analyse --memory-limit=-1 --xdebug", "tests": "phpunit --fail-on-warning", "mutation": "vendor/bin/roave-infection-static-analysis-plugin --only-covered --test-framework-options=\"--testsuite=unit\"", "all": "composer psalm && composer stan && composer tests && composer mutation && composer cs && composer security", diff --git a/phpstan.neon b/phpstan.neon index ae5e870..8986f67 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -29,14 +29,6 @@ parameters: message: '#Instanceof between cebe\\openapi\\spec\\MediaType and cebe\\openapi\\spec\\MediaType will always evaluate to true\.#' paths: - %currentWorkingDirectory%/src/Specification/SpecificationParser.php - - - message: '#SpecificationLoaderTest\.php:55\)\) of method#' - paths: - - %currentWorkingDirectory%/test/functional/Specification/SpecificationLoaderTest.php - - - message: '#TestApiServerCodeGeneratorFactory\.php:55\)\) of method#' - paths: - - %currentWorkingDirectory%/test/generation/TestApiServerCodeGeneratorFactory.php - message: '#OnMoon\\OpenApiServerBundle\\Router\\RouteLoader::__construct\(\) does not call parent constructor from Symfony\\Component\\Config\\Loader\\Loader\.#' paths: diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 771ca8e..edc5c1b 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -89,7 +89,7 @@ public function handle(Request $request): Response $requestDto = $this->createRequestDto($request, $operation, $inputDtoClass); } - $this->eventDispatcher->dispatch(new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler)); + $this->eventDispatcher->dispatch(new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler, $request)); $responseDto = $this->executeRequestHandler($requestHandler, $methodName, $requestDto); $this->eventDispatcher->dispatch(new ResponseDtoEvent($responseDto, $operationId, $specification)); diff --git a/src/Event/Server/RequestDtoEvent.php b/src/Event/Server/RequestDtoEvent.php index de28ae1..f1136db 100644 --- a/src/Event/Server/RequestDtoEvent.php +++ b/src/Event/Server/RequestDtoEvent.php @@ -7,6 +7,7 @@ use OnMoon\OpenApiServerBundle\Interfaces\Dto; use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler; use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; +use Symfony\Component\HttpFoundation\Request; use Symfony\Contracts\EventDispatcher\Event; /** @@ -29,13 +30,15 @@ final class RequestDtoEvent extends Event private string $operationId; private Specification $specification; private RequestHandler $requestHandler; + private Request $request; - public function __construct(?Dto $requestDto, string $operationId, Specification $specification, RequestHandler $requestHandler) + public function __construct(?Dto $requestDto, string $operationId, Specification $specification, RequestHandler $requestHandler, Request $request) { $this->requestDto = $requestDto; $this->operationId = $operationId; $this->specification = $specification; $this->requestHandler = $requestHandler; + $this->request = $request; } public function getRequestDto(): ?Dto @@ -57,4 +60,9 @@ public function getRequestHandler(): RequestHandler { return $this->requestHandler; } + + public function getRequest(): Request + { + return $this->request; + } } diff --git a/test/unit/Event/Server/RequestDtoEventTest.php b/test/unit/Event/Server/RequestDtoEventTest.php index 6126b14..a542a78 100644 --- a/test/unit/Event/Server/RequestDtoEventTest.php +++ b/test/unit/Event/Server/RequestDtoEventTest.php @@ -11,6 +11,7 @@ use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; /** * @covers \OnMoon\OpenApiServerBundle\Event\Server\RequestDtoEvent @@ -19,6 +20,7 @@ final class RequestDtoEventTest extends TestCase { public function testRequestDtoEventGettersReturnCorrectValues(): void { + $request = new Request(); $requestDto = new class () implements Dto { /** * @return mixed[] @@ -41,27 +43,30 @@ public static function fromArray(array $data): Dto $requestHandler = new class () implements RequestHandler{ }; - $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler); + $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler, $request); Assert::assertEquals($requestDto, $requestDtoEvent->getRequestDto()); Assert::assertEquals($operationId, $requestDtoEvent->getOperationId()); Assert::assertEquals($specification, $requestDtoEvent->getSpecification()); Assert::assertEquals($requestHandler, $requestDtoEvent->getRequestHandler()); + Assert::assertEquals($request, $requestDtoEvent->getRequest()); } public function testRequestDtoEventGettersWhenRequestDtoNull(): void { + $request = new Request(); $requestDto = null; $operationId = '12345'; $specification = new Specification([], new OpenApi([])); $requestHandler = new class () implements RequestHandler{ }; - $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler); + $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler, $request); Assert::assertNull($requestDtoEvent->getRequestDto()); Assert::assertEquals($operationId, $requestDtoEvent->getOperationId()); Assert::assertEquals($specification, $requestDtoEvent->getSpecification()); Assert::assertEquals($requestHandler, $requestDtoEvent->getRequestHandler()); + Assert::assertEquals($request, $requestDtoEvent->getRequest()); } }