Skip to content

Commit

Permalink
feat(404-prepartor): revert changes on 404 prepartor
Browse files Browse the repository at this point in the history
  • Loading branch information
sidux committed Jun 27, 2024
1 parent d617b21 commit ab566c6
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/Preparator/Error404Preparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
namespace APITester\Preparator;

use APITester\Definition\Collection\Operations;
use APITester\Definition\Example\OperationExample;
use APITester\Definition\Example\ResponseExample;
use APITester\Definition\Response as DefinitionResponse;
use APITester\Test\TestCase;

final class Error404Preparator extends TestCasesPreparator
{
public const INT32_MAX = 2147483647;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -41,21 +40,13 @@ private function prepareTestCase(DefinitionResponse $response): array

$testcases = [];

$pathParameters = array_map(
static fn ($parameter) => $parameter->getName(),
$operation->getPathParameters()
->toArray()
);
$pathParameters = array_fill_keys(array_values($pathParameters), self::INT32_MAX);

if ($operation->getRequestBodies()->count() === 0) {
$testcases[] = $this->buildTestCase(
$operation->getExample()
->withName('RandomPath')
->setPathParameters($pathParameters)
OperationExample::create('RandomPath', $operation)
->setForceRandom()
->setResponse(
ResponseExample::create()
->setStatusCode('404')
->setStatusCode($this->config->response->getStatusCode() ?? '404')
->setHeaders($this->config->response->headers ?? [])
->setContent($this->config->response->body ?? $response->getDescription())
)
Expand All @@ -64,12 +55,11 @@ private function prepareTestCase(DefinitionResponse $response): array

foreach ($operation->getRequestBodies() as $ignored) {
$testcases[] = $this->buildTestCase(
$operation->getExample()
->withName('RandomPath')
->setPathParameters($pathParameters)
OperationExample::create('RandomPath', $operation)
->setForceRandom()
->setResponse(
ResponseExample::create()
->setStatusCode('404')
->setStatusCode($this->config->response->getStatusCode() ?? '404')
->setHeaders($this->config->response->headers ?? [])
->setContent($this->config->response->body ?? $response->getDescription())
)
Expand Down

0 comments on commit ab566c6

Please sign in to comment.