Skip to content

Commit 9fd1fed

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

File tree

4 files changed

+6
-75
lines changed

4 files changed

+6
-75
lines changed

src/Config/Filters.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,6 @@ public function includes(Filterable $object): bool
143143
return $include;
144144
}
145145

146-
public function excludes(Filterable $object): bool
147-
{
148-
foreach ($this->getExclude() as $item) {
149-
foreach ($item as $key => $value) {
150-
[$operator, $value] = $this->handleTags($value);
151-
if ($object->has($key, $value, $operator)) {
152-
return true;
153-
}
154-
}
155-
}
156-
157-
return false;
158-
}
159-
160146
/**
161147
* @return array{'exclude': ?array<int, array<string, string>>}
162148
*/
@@ -174,9 +160,11 @@ private function handleTags(string|int|TaggedValue $value): array
174160
$operator = '=';
175161

176162
if ($value instanceof TaggedValue) {
177-
if ($value->getTag() === 'NOT') {
178-
$operator = '!=';
179-
}
163+
match ($value->getTag()) {
164+
'NOT' => $operator = '!=',
165+
'IN' => $operator = 'contains',
166+
default => $operator,
167+
};
180168
$value = (string) $value->getValue();
181169
}
182170

src/Preparator/Error400Preparator.php

-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ protected function getStatusCode(): string
118118
*/
119119
private function prepareTestCases(Operation $operation): array
120120
{
121-
if ($this->config->filters->excludes($operation)) {
122-
return [];
123-
}
124-
125121
$requiredParams = $operation->getParameters(true);
126122

127123
return array_merge(

src/Util/Traits/FilterableTrait.php

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ 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;
17-
}
18-
1913
if (str_contains($prop, '*')) {
2014
$operator = 'contains';
2115
}

tests/Preparator/Error400MissingRequiredFieldsPreparatorTest.php

+1-48
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class Error400MissingRequiredFieldsPreparatorTest extends \PHPUnit\Framewo
2222
* @dataProvider getData
2323
*
2424
* @param array<string, array<mixed>> $config
25-
* @param TestCase[] $expected
25+
* @param TestCase[] $expected
2626
*/
2727
public function test(Api $api, array $expected, array $config = []): void
2828
{
@@ -165,52 +165,5 @@ public function getData(): iterable
165165
),
166166
],
167167
];
168-
169-
yield 'openapi endpoint is ignored' => [
170-
Api::create()
171-
->addOperation(
172-
Operation::create(
173-
'test',
174-
'/test',
175-
'POST'
176-
)
177-
->addRequestBody(
178-
(new Body(
179-
new Schema([
180-
'type' => 'object',
181-
'properties' => [
182-
'foo' => [
183-
'type' => 'string',
184-
],
185-
'bar' => [
186-
'type' => 'string',
187-
],
188-
],
189-
'required' => ['foo'],
190-
]),
191-
'application/json'
192-
))
193-
)
194-
->addExample(
195-
OperationExample::create('foo')
196-
->setBodyContent([
197-
'foo' => 'foo_body1',
198-
'bar' => 'bar_body1',
199-
])
200-
->setQueryParameter('foo_query', 'foo1')
201-
)->setExtensions([
202-
'x-usecase' => 'UseCaseName',
203-
])
204-
),
205-
[
206-
],
207-
[
208-
'filters' => [
209-
'exclude' => [[
210-
'extensions' => 'x-usecase',
211-
]],
212-
],
213-
],
214-
];
215168
}
216169
}

0 commit comments

Comments
 (0)