diff --git a/src/Config/Filters.php b/src/Config/Filters.php index 54e92a8..b232d1c 100644 --- a/src/Config/Filters.php +++ b/src/Config/Filters.php @@ -5,8 +5,10 @@ namespace APITester\Config; use APITester\Util\Filterable; +use OC\BusinessRules\Entities\Security\OAuth2\InvalidScopeException; use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\Yaml\Yaml; +use UnhandledMatchError; final class Filters { @@ -174,9 +176,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(); } diff --git a/src/Util/Traits/FilterableTrait.php b/src/Util/Traits/FilterableTrait.php index 1334c99..812886b 100644 --- a/src/Util/Traits/FilterableTrait.php +++ b/src/Util/Traits/FilterableTrait.php @@ -10,10 +10,12 @@ public function has(string $prop, $value, string $operator = '='): bool { $self = collect([$this]); - $object = $self->whereNotNull($prop) - ->first(); - if (is_array($object->{$prop}) && array_key_exists((string) $value, $object->{$prop})) { - return true; + if ($operator === 'contains') { + $object = $self->whereNotNull($prop) + ->first(); + if (is_array($object->{$prop}) && array_key_exists((string) $value, $object->{$prop})) { + return true; + } } if (str_contains($prop, '*')) { diff --git a/tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php b/tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php index 2455f13..b78910c 100644 --- a/tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php +++ b/tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php @@ -15,6 +15,7 @@ use APITester\Test\TestCase; use APITester\Util\Assert; use cebe\openapi\spec\Schema; +use Symfony\Component\Yaml\Tag\TaggedValue; final class Error400MissingRequiredFieldsPreparatorTest extends \PHPUnit\Framework\TestCase { @@ -206,9 +207,11 @@ public function getData(): iterable ], [ 'filters' => [ - 'exclude' => [[ - 'extensions' => 'x-usecase', - ]], + 'exclude' => [ + [ + 'extensions' => new TaggedValue('IN', 'x-usecase'), + ], + ], ], ], ];