Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(404-prepartor): handle examples for 404 #62

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Definition/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ public function setParametersIn(Parameters $parameters, string $in): self
return $this;
}

public function getExample(?string $name = null): OperationExample
public function getExample(?string $name = null, mixed $default = null): OperationExample
{
$examples = $this->getExamples();
if ($name !== null) {
return $examples
->get($name)
->get($name, $default)
;
}

Expand Down
20 changes: 5 additions & 15 deletions src/Preparator/Error404Preparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,13 @@

$testcases = [];

if ($operation->getRequestBodies()->count() === 0) {
$testcases[] = $this->buildTestCase(
OperationExample::create('RandomPath', $operation)
->setForceRandom()
->setResponse(
ResponseExample::create()
->setStatusCode($this->config->response->getStatusCode() ?? '404')
->setHeaders($this->config->response->headers ?? [])
->setContent($this->config->response->body ?? $response->getDescription())
)
foreach (range(1, $operation->getRequestBodies()->count() ?: 1) as $ignored) {

Check failure on line 43 in src/Preparator/Error404Preparator.php

View workflow job for this annotation

GitHub Actions / PHPStan

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.
$notFoundExample = $operation->getExample(
'404',
OperationExample::create('RandomPath', $operation)->setForceRandom()
);
}

foreach ($operation->getRequestBodies() as $ignored) {
$testcases[] = $this->buildTestCase(
OperationExample::create('RandomPath', $operation)
->setForceRandom()
$notFoundExample
->setResponse(
ResponseExample::create()
->setStatusCode($this->config->response->getStatusCode() ?? '404')
Expand Down
Loading