Skip to content

Commit

Permalink
Merge pull request #70 from OpenClassrooms/update_400_preparator_excl…
Browse files Browse the repository at this point in the history
…usion

feat(api tester): use filters to exclude openapi endpoints
  • Loading branch information
Dzov authored Nov 29, 2024
2 parents 699dcda + 101e337 commit ac5b414
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 92 deletions.
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,
],
];
}
}

0 comments on commit ac5b414

Please sign in to comment.