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(api tester): use filters to exclude openapi endpoints #70

Merged
merged 2 commits into from
Nov 29, 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
8 changes: 5 additions & 3 deletions src/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ private function handleTags(string|int|TaggedValue $value): array
$operator = '=';

if ($value instanceof TaggedValue) {
if ($value->getTag() === 'NOT') {
$operator = '!=';
}
match ($value->getTag()) {
'NOT' => $operator = '!=',
'IN' => $operator = 'contains',
default => $operator,
};
$value = (string) $value->getValue();
}

Expand Down
9 changes: 0 additions & 9 deletions src/Preparator/Config/Error400BadFormatsPreparatorConfig.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Preparator/Config/Error400BadTypesPreparatorConfig.php

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/Preparator/Config/Error400PreparatorConfig.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Preparator/Error400Preparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
use APITester\Definition\Example\ResponseExample;
use APITester\Definition\Operation;
use APITester\Definition\Parameter;
use APITester\Preparator\Config\Error400PreparatorConfig;
use APITester\Test\TestCase;

/**
* @property Error400PreparatorConfig $config
*/
abstract class Error400Preparator extends TestCasesPreparator
{
/**
Expand Down Expand Up @@ -122,10 +118,6 @@ protected function getStatusCode(): string
*/
private function prepareTestCases(Operation $operation): array
{
if ($this->config->excludeOpenApiEndpoints
&& isset($operation->getExtensions()['x-usecase'])) {
return [];
}
$requiredParams = $operation->getParameters(true);

return array_merge(
Expand Down
1 change: 1 addition & 0 deletions src/Util/Traits/FilterableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trait FilterableTrait
public function has(string $prop, $value, string $operator = '='): bool
{
$self = collect([$this]);

if (str_contains($prop, '*')) {
$operator = 'contains';
}
Expand Down
45 changes: 1 addition & 44 deletions tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Error400MissingRequiredFieldsPreparatorTest extends \PHPUnit\Framewo
* @dataProvider getData
*
* @param array<string, array<mixed>> $config
* @param TestCase[] $expected
* @param TestCase[] $expected
*/
public function test(Api $api, array $expected, array $config = []): void
{
Expand Down Expand Up @@ -165,48 +165,5 @@ public function getData(): iterable
),
],
];

yield 'openapi endpoint is ignored' => [
Api::create()
->addOperation(
Operation::create(
'test',
'/test',
'POST'
)
->addRequestBody(
(new Body(
new Schema([
'type' => 'object',
'properties' => [
'foo' => [
'type' => 'string',
],
'bar' => [
'type' => 'string',
],
],
'required' => ['foo'],
]),
'application/json'
))
)
->addExample(
OperationExample::create('foo')
->setBodyContent([
'foo' => 'foo_body1',
'bar' => 'bar_body1',
])
->setQueryParameter('foo_query', 'foo1')
)->setExtensions([
'x-usecase' => 'UseCaseName',
])
),
[
],
[
'excludeOpenApiEndpoints' => true,
],
];
}
}
Loading