Skip to content

Commit

Permalink
feat(api tester): use IN tag to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzov committed Nov 29, 2024
1 parent 989516b commit c740ae1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}

Expand Down
10 changes: 6 additions & 4 deletions src/Util/Traits/FilterableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '*')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -206,9 +207,11 @@ public function getData(): iterable
],
[
'filters' => [
'exclude' => [[
'extensions' => 'x-usecase',
]],
'exclude' => [
[
'extensions' => new TaggedValue('IN', 'x-usecase'),
],
],
],
],
];
Expand Down

0 comments on commit c740ae1

Please sign in to comment.