Skip to content

Commit c740ae1

Browse files
committed
feat(api tester): use IN tag to filter
1 parent 989516b commit c740ae1

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/Config/Filters.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace APITester\Config;
66

77
use APITester\Util\Filterable;
8+
use OC\BusinessRules\Entities\Security\OAuth2\InvalidScopeException;
89
use Symfony\Component\Yaml\Tag\TaggedValue;
910
use Symfony\Component\Yaml\Yaml;
11+
use UnhandledMatchError;
1012

1113
final class Filters
1214
{
@@ -174,9 +176,11 @@ private function handleTags(string|int|TaggedValue $value): array
174176
$operator = '=';
175177

176178
if ($value instanceof TaggedValue) {
177-
if ($value->getTag() === 'NOT') {
178-
$operator = '!=';
179-
}
179+
match ($value->getTag()) {
180+
'NOT' => $operator = '!=',
181+
'IN' => $operator = 'contains',
182+
default => $operator,
183+
};
180184
$value = (string) $value->getValue();
181185
}
182186

src/Util/Traits/FilterableTrait.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ public function has(string $prop, $value, string $operator = '='): bool
1010
{
1111
$self = collect([$this]);
1212

13-
$object = $self->whereNotNull($prop)
14-
->first();
15-
if (is_array($object->{$prop}) && array_key_exists((string) $value, $object->{$prop})) {
16-
return true;
13+
if ($operator === 'contains') {
14+
$object = $self->whereNotNull($prop)
15+
->first();
16+
if (is_array($object->{$prop}) && array_key_exists((string) $value, $object->{$prop})) {
17+
return true;
18+
}
1719
}
1820

1921
if (str_contains($prop, '*')) {

tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use APITester\Test\TestCase;
1616
use APITester\Util\Assert;
1717
use cebe\openapi\spec\Schema;
18+
use Symfony\Component\Yaml\Tag\TaggedValue;
1819

1920
final class Error400MissingRequiredFieldsPreparatorTest extends \PHPUnit\Framework\TestCase
2021
{
@@ -206,9 +207,11 @@ public function getData(): iterable
206207
],
207208
[
208209
'filters' => [
209-
'exclude' => [[
210-
'extensions' => 'x-usecase',
211-
]],
210+
'exclude' => [
211+
[
212+
'extensions' => new TaggedValue('IN', 'x-usecase'),
213+
],
214+
],
212215
],
213216
],
214217
];

0 commit comments

Comments
 (0)