From 8dba2a4afce74a9f6f6d04bb432d53b89ccae2f6 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Fri, 16 Feb 2024 21:07:39 +0200 Subject: [PATCH 1/2] ORC-400: Add headers checks to existing composer behat package - update tests Signed-off-by: Serhii Donii --- .gitignore | 4 + .infrastructure/docker/Dockerfile | 10 ++ composer.json | 1 + docker-compose.yaml | 14 +++ src/Context/ApiContext.php | 6 +- .../ResetManager/DoctrineResetManager.php | 1 + tests/Unit/Context/AbstractApiContextTest.php | 41 ++++++ tests/Unit/Context/ApiContextTest.php | 55 +++----- tests/Unit/Context/GivenApiContextsTest.php | 66 ++++++++++ tests/Unit/Context/InitApiContextsTest.php | 60 +++++++++ tests/Unit/Context/ResponseHasHeaderTest.php | 58 +++++++++ tests/Unit/Context/ThenApiContextTest.php | 119 ++++++++++++++++++ tests/Unit/Context/WhenApiContextsTest.php | 116 +++++++++++++++++ .../WhenSendRequestToRouteApiContextsTest.php | 35 ++++++ 14 files changed, 549 insertions(+), 37 deletions(-) create mode 100644 .infrastructure/docker/Dockerfile create mode 100644 docker-compose.yaml create mode 100644 tests/Unit/Context/AbstractApiContextTest.php create mode 100644 tests/Unit/Context/GivenApiContextsTest.php create mode 100644 tests/Unit/Context/InitApiContextsTest.php create mode 100644 tests/Unit/Context/ResponseHasHeaderTest.php create mode 100644 tests/Unit/Context/ThenApiContextTest.php create mode 100644 tests/Unit/Context/WhenApiContextsTest.php create mode 100644 tests/Unit/Context/WhenSendRequestToRouteApiContextsTest.php diff --git a/.gitignore b/.gitignore index 0f35a13..42c2f38 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ /.idea/ /package-lock.json .DS_Store +/phpunit.xml +/phpcs.xml +/phpstan.neon +/coverage diff --git a/.infrastructure/docker/Dockerfile b/.infrastructure/docker/Dockerfile new file mode 100644 index 0000000..22e32ad --- /dev/null +++ b/.infrastructure/docker/Dockerfile @@ -0,0 +1,10 @@ +ARG from_image + +FROM $from_image + +ENV XDEBUG_MODE=off + +RUN apk add --no-cache bash linux-headers $PHPIZE_DEPS \ + && pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && curl --silent https://getcomposer.org/composer-stable.phar -o /usr/bin/composer && chmod a+x /usr/bin/composer diff --git a/composer.json b/composer.json index 01dacca..4f892e8 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,7 @@ "code-style": "./vendor/bin/phpcs", "code-style-fix": "./vendor/bin/phpcbf", "phpunit": "./vendor/bin/phpunit", + "phpunit-html-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=coverage", "dev-checks": [ "composer validate", "@phpstan", diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..cf844e5 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,14 @@ +version: '3.9' + +services: + php80: + build: + context: .infrastructure + dockerfile: docker/Dockerfile + args: + from_image: php:8.0-fpm-alpine + working_dir: /app + environment: + PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/vendor/bin" + volumes: + - ./:/app diff --git a/src/Context/ApiContext.php b/src/Context/ApiContext.php index 7b06e69..b68929e 100644 --- a/src/Context/ApiContext.php +++ b/src/Context/ApiContext.php @@ -6,8 +6,8 @@ use Behat\Behat\Context\Context; use Behat\Gherkin\Node\PyStringNode; -use BehatApiContext\Service\StringManager; use BehatApiContext\Service\ResetManager\ResetManagerInterface; +use BehatApiContext\Service\StringManager; use RuntimeException; use SimilarArrays\SimilarArray; use Symfony\Component\HttpFoundation\Request; @@ -136,7 +136,7 @@ public function iSendRequestToRoute( if (Request::METHOD_GET === $method) { $queryString = http_build_query($this->requestParams); - } elseif (Request::METHOD_POST === $method || Request::METHOD_PATCH === $method || Request::METHOD_PUT === $method) { + } elseif (in_array($method, [Request::METHOD_POST, Request::METHOD_PATCH, Request::METHOD_PUT], true)) { $postFields = $this->requestParams; } @@ -374,7 +374,9 @@ protected function convertRunnableCodeParams(array $requestParams): array $command = substr(trim($value), 1, -1); try { + // phpcs:disable $resultValue = eval('return ' . $command . ';'); + // phpcs:enable } catch (Throwable $exception) { throw new RuntimeException( sprintf( diff --git a/src/Service/ResetManager/DoctrineResetManager.php b/src/Service/ResetManager/DoctrineResetManager.php index 089fe1b..2ca27bd 100644 --- a/src/Service/ResetManager/DoctrineResetManager.php +++ b/src/Service/ResetManager/DoctrineResetManager.php @@ -25,6 +25,7 @@ public function reset(KernelInterface $kernel): void foreach ($entityManagers as $entityManagerId) { if ($container->initialized($entityManagerId)) { $em = $container->get($entityManagerId); +// assert($em instanceof EntityManagerInterface); $em->clear(); $connection = $em->getConnection(); diff --git a/tests/Unit/Context/AbstractApiContextTest.php b/tests/Unit/Context/AbstractApiContextTest.php new file mode 100644 index 0000000..28e2d60 --- /dev/null +++ b/tests/Unit/Context/AbstractApiContextTest.php @@ -0,0 +1,41 @@ +createMock(RequestStack::class); + $this->apiContext = new ApiContext($this->configureRouter(), $requestStackMock, $this->getKernelMock()); + } + + protected function configureRouter(): RouterInterface + { + /** @var RouterInterface $routerMock */ + $routerMock = $this->createMock(RouterInterface::class); + + return $routerMock; + } + + protected function getKernelMock(): KernelInterface + { + $kernel = $this->createMock(KernelInterface::class); + assert($kernel instanceof KernelInterface); + + return $kernel; + } +} diff --git a/tests/Unit/Context/ApiContextTest.php b/tests/Unit/Context/ApiContextTest.php index 99ba9b0..63912fa 100644 --- a/tests/Unit/Context/ApiContextTest.php +++ b/tests/Unit/Context/ApiContextTest.php @@ -5,27 +5,12 @@ namespace BehatApiContext\Tests\Unit\Context; use Behat\Gherkin\Node\PyStringNode; -use BehatApiContext\Context\ApiContext; -use PHPUnit\Framework\TestCase; use RuntimeException; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpKernel\KernelInterface; -use Symfony\Component\Routing\RouterInterface; -class ApiContextTest extends TestCase +class ApiContextTest extends AbstractApiContextTest { private const PARAMS_VALUES = 'paramsValues'; private const INITIAL_PARAM_VALUE = 'initialParamValue'; - private ApiContext $apiContext; - - protected function setUp(): void - { - $routerMock = $this->createMock(RouterInterface::class); - $requestStackMock = $this->createMock(RequestStack::class); - $kernelMock = $this->createMock(KernelInterface::class); - - $this->apiContext = new ApiContext($routerMock, $requestStackMock, $kernelMock); - } /** * @param PyStringNode $paramsValues @@ -47,40 +32,40 @@ public function testTheRequestContainsParamsSuccess(PyStringNode $paramsValues, $this->assertEquals( 10, - strlen((string)$this->apiContext->geRequestParams()['dateFrom']) + strlen((string)$this->apiContext->geRequestParams()['dateFrom']), ); $this->assertEquals( 10, - strlen((string)$this->apiContext->geRequestParams()['levelOne']['dateFrom']) + strlen((string)$this->apiContext->geRequestParams()['levelOne']['dateFrom']), ); $this->assertEquals( 10, - strlen((string)$this->apiContext->geRequestParams()['levelOne']['levelTwo']['dateFrom']) + strlen((string)$this->apiContext->geRequestParams()['levelOne']['levelTwo']['dateFrom']), ); $this->assertTrue( str_contains( $paramsValues->getStrings()[1], - $this->apiContext->geRequestParams()['tripId'] - ) + $this->apiContext->geRequestParams()['tripId'], + ), ); $this->assertTrue( str_contains( $paramsValues->getStrings()[2], - strval($this->apiContext->geRequestParams()['dateTo']) - ) + strval($this->apiContext->geRequestParams()['dateTo']), + ), ); $this->assertTrue( str_contains( $paramsValues->getStrings()[5], - strval($this->apiContext->geRequestParams()['levelOne']['dateTo']) - ) + strval($this->apiContext->geRequestParams()['levelOne']['dateTo']), + ), ); $this->assertTrue( str_contains( $paramsValues->getStrings()[8], - strval($this->apiContext->geRequestParams()['levelOne']['levelTwo']['dateTo']) - ) + strval($this->apiContext->geRequestParams()['levelOne']['levelTwo']['dateTo']), + ), ); } @@ -115,7 +100,7 @@ public function getTheRequestContainsParamsSuccess(): array ' }', '}', ], - 12 + 12, ), self::INITIAL_PARAM_VALUE => '<(new DateTimeImmutable())->getTimestamp()>', ], @@ -134,8 +119,8 @@ public function getTheRequestContainsParamsRuntimeException(): array ' "dateFrom": "<(new DateTimeImutable())->getTimestamp()>"', '}', ], - 12 - ) + 12, + ), ], [ self::PARAMS_VALUES => new PyStringNode( @@ -146,8 +131,8 @@ public function getTheRequestContainsParamsRuntimeException(): array ' "dateFrom": "<(DateTimeImmutable)->getTimestamp()>"', '}', ], - 12 - ) + 12, + ), ], [ self::PARAMS_VALUES => new PyStringNode( @@ -162,7 +147,7 @@ public function getTheRequestContainsParamsRuntimeException(): array ' }', '}', ], - 12 + 12, ), ], [ @@ -174,8 +159,8 @@ public function getTheRequestContainsParamsRuntimeException(): array ' "dateFrom": "<>"', '}', ], - 12 - ) + 12, + ), ], ]; } diff --git a/tests/Unit/Context/GivenApiContextsTest.php b/tests/Unit/Context/GivenApiContextsTest.php new file mode 100644 index 0000000..b389294 --- /dev/null +++ b/tests/Unit/Context/GivenApiContextsTest.php @@ -0,0 +1,66 @@ +apiContext); + $headersProp = $reflectionClass->getProperty('headers'); + $headersProp->setAccessible(true); + + $this->assertEmpty($headersProp->getValue($this->apiContext)); + + $this->apiContext->theRequestHeaderContains('key', 'value'); + + $this->assertNotEmpty($headersProp->getValue($this->apiContext)); + + $headersProp->setAccessible(false); + } + + /** + * @throws ReflectionException + */ + public function testGivenMultilineHeader(): void + { + $reflectionClass = new ReflectionClass($this->apiContext); + $headersProp = $reflectionClass->getProperty('headers'); + $headersProp->setAccessible(true); + + $this->assertEmpty($headersProp->getValue($this->apiContext)); + + $this->apiContext->theRequestHeaderContainsMultiline('key', new PyStringNode(['value', 'value'], 2)); + + $this->assertNotEmpty($headersProp->getValue($this->apiContext)); + + $headersProp->setAccessible(false); + } + + public function testGivenIps(): void + { + $reflectionClass = new ReflectionClass($this->apiContext); + $serverParamsProp = $reflectionClass->getProperty('serverParams'); + $serverParamsProp->setAccessible(true); + + $params = $serverParamsProp->getValue($this->apiContext); + $this->assertIsArray($params); + $this->assertArrayNotHasKey('REMOTE_ADDR', $params); + + $this->apiContext->theRequestIpIs('10.10.10.10'); + + $params = $serverParamsProp->getValue($this->apiContext); + $this->assertIsArray($params); + $this->assertArrayHasKey('REMOTE_ADDR', $params); + $this->assertEquals('10.10.10.10', $params['REMOTE_ADDR']); + } +} diff --git a/tests/Unit/Context/InitApiContextsTest.php b/tests/Unit/Context/InitApiContextsTest.php new file mode 100644 index 0000000..39b7a90 --- /dev/null +++ b/tests/Unit/Context/InitApiContextsTest.php @@ -0,0 +1,60 @@ +apiContext); + $savedValuesProp = $reflectionClass->getProperty('savedValues'); + $savedValuesProp->setAccessible(true); + $headersProp = $reflectionClass->getProperty('headers'); + $headersProp->setAccessible(true); + $serverParamsProp = $reflectionClass->getProperty('serverParams'); + $serverParamsProp->setAccessible(true); + $requestParamsProp = $reflectionClass->getProperty('requestParams'); + $requestParamsProp->setAccessible(true); + + $savedValuesProp->setValue($this->apiContext, ['key' => 'value']); + $headersProp->setValue($this->apiContext, ['key' => 'value']); + $serverParamsProp->setValue($this->apiContext, ['key' => 'value']); + $requestParamsProp->setValue($this->apiContext, ['key' => 'value']); + + $this->assertNotEmpty($savedValuesProp->getValue($this->apiContext)); + $this->assertNotEmpty($headersProp->getValue($this->apiContext)); + $this->assertNotEmpty($serverParamsProp->getValue($this->apiContext)); + $this->assertNotEmpty($requestParamsProp->getValue($this->apiContext)); + + $this->apiContext->beforeScenario(); + $this->assertEmpty($savedValuesProp->getValue($this->apiContext)); + $this->assertEmpty($headersProp->getValue($this->apiContext)); + $this->assertEmpty($serverParamsProp->getValue($this->apiContext)); + $this->assertEmpty($requestParamsProp->getValue($this->apiContext)); + } + + public function testAddResetManager(): void + { + /** @var ResetManagerInterface $resetManager */ + $resetManager = $this->createMock(ResetManagerInterface::class); + + $reflectionClass = new ReflectionClass($this->apiContext); + $resetManagersProp = $reflectionClass->getProperty('resetManagers'); + $resetManagersProp->setAccessible(true); + + $this->assertEmpty($resetManagersProp->getValue($this->apiContext)); + + $this->apiContext->addKernelResetManager($resetManager); + + $this->assertNotEmpty($resetManagersProp->getValue($this->apiContext)); + } +} diff --git a/tests/Unit/Context/ResponseHasHeaderTest.php b/tests/Unit/Context/ResponseHasHeaderTest.php new file mode 100644 index 0000000..0402ea0 --- /dev/null +++ b/tests/Unit/Context/ResponseHasHeaderTest.php @@ -0,0 +1,58 @@ +response = new Response(); + $reflectionClass = new \ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $responseProp->setValue($this->apiContext, $this->response); + $responseProp->setAccessible(false); + } + + public function testResponseHeadersContainsException(): void + { + $this->expectException(RuntimeException::class); + $this->apiContext->theResponseHeadersContains('Content-Type', 'application/json'); + } + + public function testExceptionWhenHeaderValuesDoesNotEquals(): void + { + $this->expectException(RuntimeException::class); + $reflectionClass = new \ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $response = new Response('', 200, ['Content-Type' => 'application/xml']); + $response->headers->set('X-Content-Type', 'application/xml'); + $responseProp->setValue($this->apiContext, $response); + + $this->expectException(RuntimeException::class); + $this->apiContext->theResponseHeadersContains('X-Content-Type', 'application/json'); + } + + public function testWhenHeaderValuesDoesNotEqualsSuccess(): void + { + $this->expectException(RuntimeException::class); + $reflectionClass = new \ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $response = new Response('', 200, ['Content-Type' => 'application/xml']); + $response->headers->set('X-Content-Type', 'application/xml'); + $responseProp->setValue($this->apiContext, $response); + + $this->apiContext->theResponseHeadersContains('X-Content-Type', 'application/json'); + } +} diff --git a/tests/Unit/Context/ThenApiContextTest.php b/tests/Unit/Context/ThenApiContextTest.php new file mode 100644 index 0000000..ed42306 --- /dev/null +++ b/tests/Unit/Context/ThenApiContextTest.php @@ -0,0 +1,119 @@ +apiContext); + $method = $reflectionClass->getProperty('response'); + $method->setAccessible(true); + $method->setValue($this->apiContext, $response); + + $this->apiContext->responseStatusCodeShouldBe('200'); + + $this->expectException(\RuntimeException::class); + $this->apiContext->responseStatusCodeShouldBe('201'); + } + + public function testResponseIsJson(): void + { + $response = new Response(json_encode(['status' => 'OK']), 200); + + $reflectionClass = new ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $responseProp->setValue($this->apiContext, $response); + $this->apiContext->responseIsJson(); + + $response = new Response('', 200); + $responseProp->setValue($this->apiContext, $response); + $this->expectException(JsonException::class); + $this->apiContext->responseIsJson(); + } + + public function testExceptionWhenResponseIsEmptyJson(): void + { + $reflectionClass = new ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $response = new Response('{}', 200); + $responseProp->setValue($this->apiContext, $response); + + $this->expectException(RuntimeException::class); + $this->apiContext->responseIsJson(); + } + + public function testResponseIsEmpty(): void + { + $reflectionClass = new ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $response = new Response('', 200); + $responseProp->setValue($this->apiContext, $response); + + $this->apiContext->responseEmpty(); + + $response = new Response('{}', 200); + $responseProp->setValue($this->apiContext, $response); + + $this->expectException(RuntimeException::class); + $this->apiContext->responseEmpty(); + } + + public function testResponseShouldBeJson(): void + { + $response = new Response(json_encode(['status' => 'OK']), 200); + + $reflectionClass = new ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $responseProp->setValue($this->apiContext, $response); + + $this->apiContext->responseShouldBeJson(new PyStringNode(['{"status": "OK"}'], 1)); + + $response = new Response('{}', 200); + $responseProp->setValue($this->apiContext, $response); + $this->expectException(RuntimeException::class); + $this->apiContext->responseShouldBeJson(new PyStringNode(['{"status": "OK"}'], 1)); + } + + public function testResponseShouldBeJsonWithVariableFields(): void + { + $response = new Response('{"message": "Hello, World!"}'); + $reflection = new \ReflectionClass($this->apiContext); + $property = $reflection->getProperty('response'); + $property->setAccessible(true); + $property->setValue($this->apiContext, $response); + + $variableFields = 'message, world'; + $string = new PyStringNode(['{"message": "Hello, World!"}'], 0); + + try { + $this->apiContext->responseShouldBeJsonWithVariableFields($variableFields, $string); + } catch (Throwable $e) { + $this->assertStringContainsString( + 'Expected JSON is not similar to the actual JSON with variable fields:', + $e->getMessage(), + ); + $this->assertInstanceOf(RuntimeException::class, $e); + } + + $this->expectException(RuntimeException::class); + $response = new Response(''); + $property->setValue($this->apiContext, $response); + $this->apiContext->responseShouldBeJsonWithVariableFields($variableFields, $string); + } +} diff --git a/tests/Unit/Context/WhenApiContextsTest.php b/tests/Unit/Context/WhenApiContextsTest.php new file mode 100644 index 0000000..4c48e04 --- /dev/null +++ b/tests/Unit/Context/WhenApiContextsTest.php @@ -0,0 +1,116 @@ + + */ + public function methods(): array + { + return [ + [Request::METHOD_GET], + [Request::METHOD_POST], + ]; + } + + protected function setUp(): void + { + $this->route = new Route( + '/api/users/{id}', + ['_controller' => 'App\Controller\UserController::get'], + ['id' => '\d+'], + ); + + if ('testExceptionWhenRouteNotFound' === $this->getName()) { + $this->invalidRouteMock = true; + } + + parent::setUp(); + } + + /** + * @dataProvider methods + */ + public function testSendRequestToRoute(string $method): void + { + $this->apiContext->iSendRequestToRoute($method, '/api/users/{id}'); + + $this->assertNotNull($this->response); + $this->assertNotNull($this->request); + } + + public function testExceptionWhenRouteNotFound(): void + { + $this->invalidRouteMock = true; + $this->expectException(RouteNotFoundException::class); + $this->apiContext->iSendRequestToRoute(Request::METHOD_GET, '/_api/users/{id}'); + } + + protected function configureRouter(): RouterInterface + { + $router = parent::configureRouter(); + assert($router instanceof MockObject); + + $routeCollection = new RouteCollection(); + $routeCollection->add('api_users_get', $this->route); + + $router->method('getRouteCollection') + ->willReturn( + $routeCollection, + ); + $router->expects($this->once()) + ->method('generate'); + + if (true === $this->invalidRouteMock) { + $router->expects($this->once()) + ->method('generate') + ->willThrowException(new RouteNotFoundException()); + } + + assert($router instanceof RouterInterface); + + return $router; + } + + protected function getKernelMock(): KernelInterface + { + $kernel = $this->createMock(Kernel::class); + + assert($kernel instanceof MockObject); + + if (!$this->invalidRouteMock) { + $kernel + ->expects($this->once()) + ->method('terminate') + ->will( + $this->returnCallback(function (Request $request, Response $response): void { + $this->request = $request; + $this->response = $response; + }), + ); + } + + assert($kernel instanceof KernelInterface); + + return $kernel; + } +} diff --git a/tests/Unit/Context/WhenSendRequestToRouteApiContextsTest.php b/tests/Unit/Context/WhenSendRequestToRouteApiContextsTest.php new file mode 100644 index 0000000..3a0aa04 --- /dev/null +++ b/tests/Unit/Context/WhenSendRequestToRouteApiContextsTest.php @@ -0,0 +1,35 @@ + 1]), 200); + + $reflectionClass = new \ReflectionClass($this->apiContext); + $responseProp = $reflectionClass->getProperty('response'); + $responseProp->setAccessible(true); + $responseProp->setValue($this->apiContext, $response); + + $this->apiContext->iGetParamFromJsonResponse('id', 'id_'); + $savedValuesProp = $reflectionClass->getProperty('savedValues'); + $savedValuesProp->setAccessible(true); + $this->assertArrayHasKey('id_', $savedValuesProp->getValue($this->apiContext)); + + $this->expectException(RuntimeException::class); + $this->apiContext->iGetParamFromJsonResponse('not_existed', 'id_'); + } +} From 3fcc4907f7427f72d5b4447e8607e11602f78ca8 Mon Sep 17 00:00:00 2001 From: Serhii Donii Date: Fri, 16 Feb 2024 21:10:52 +0200 Subject: [PATCH 2/2] ORC-400: Add headers checks to existing composer behat package - update tests Signed-off-by: Serhii Donii --- .../ResetManager/DoctrineResetManager.php | 1 - tests/Unit/Context/WhenApiContextsTest.php | 28 +++---------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Service/ResetManager/DoctrineResetManager.php b/src/Service/ResetManager/DoctrineResetManager.php index 2ca27bd..089fe1b 100644 --- a/src/Service/ResetManager/DoctrineResetManager.php +++ b/src/Service/ResetManager/DoctrineResetManager.php @@ -25,7 +25,6 @@ public function reset(KernelInterface $kernel): void foreach ($entityManagers as $entityManagerId) { if ($container->initialized($entityManagerId)) { $em = $container->get($entityManagerId); -// assert($em instanceof EntityManagerInterface); $em->clear(); $connection = $em->getConnection(); diff --git a/tests/Unit/Context/WhenApiContextsTest.php b/tests/Unit/Context/WhenApiContextsTest.php index 4c48e04..2adf3ac 100644 --- a/tests/Unit/Context/WhenApiContextsTest.php +++ b/tests/Unit/Context/WhenApiContextsTest.php @@ -21,17 +21,6 @@ final class WhenApiContextsTest extends AbstractApiContextTest private ?Response $response = null; private bool $invalidRouteMock = false; - /** - * @return array - */ - public function methods(): array - { - return [ - [Request::METHOD_GET], - [Request::METHOD_POST], - ]; - } - protected function setUp(): void { $this->route = new Route( @@ -47,17 +36,6 @@ protected function setUp(): void parent::setUp(); } - /** - * @dataProvider methods - */ - public function testSendRequestToRoute(string $method): void - { - $this->apiContext->iSendRequestToRoute($method, '/api/users/{id}'); - - $this->assertNotNull($this->response); - $this->assertNotNull($this->request); - } - public function testExceptionWhenRouteNotFound(): void { $this->invalidRouteMock = true; @@ -77,13 +55,15 @@ protected function configureRouter(): RouterInterface ->willReturn( $routeCollection, ); - $router->expects($this->once()) - ->method('generate'); if (true === $this->invalidRouteMock) { $router->expects($this->once()) ->method('generate') ->willThrowException(new RouteNotFoundException()); + } else { + $router->expects($this->once()) + ->method('generate') + ->willReturn('/api/users/1'); } assert($router instanceof RouterInterface);