Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swagger DocumentationNormalizer test for array collection filters #2241

Merged
merged 1 commit into from
Oct 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions tests/Swagger/Serializer/DocumentationNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1229,14 +1229,21 @@ public function testFilters()
'required' => false,
'strategy' => 'partial',
]]),
'f3' => new DummyFilter(['toto' => [
'property' => 'name',
'type' => 'array',
'is_collection' => true,
'required' => true,
'strategy' => 'exact',
]]),
];

foreach ($filters as $filterId => $filter) {
$filterLocatorProphecy->has($filterId)->willReturn(true)->shouldBeCalled();
$filterLocatorProphecy->get($filterId)->willReturn($filter)->shouldBeCalled();
}

$filterLocatorProphecy->has('f3')->willReturn(false)->shouldBeCalled();
$filterLocatorProphecy->has('f4')->willReturn(false)->shouldBeCalled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fault of this PR, but ->shouldBeCalled() should only be used when we actually want to check that a method is called. If the intention is only to mock the return value of the method, ->willReturn(...) should suffice.


$this->normalizeWithFilters($filterLocatorProphecy->reveal());
}
Expand All @@ -1261,6 +1268,13 @@ public function testFiltersWithDeprecatedFilterCollection()
'required' => false,
'strategy' => 'partial',
]]),
'f3' => new DummyFilter(['toto' => [
'property' => 'name',
'type' => 'array',
'is_collection' => true,
'required' => true,
'strategy' => 'exact',
]]),
]));
}

Expand Down Expand Up @@ -1651,7 +1665,7 @@ private function normalizeWithFilters($filterLocator)
'This is a dummy.',
null,
[],
['get' => ['method' => 'GET', 'filters' => ['f1', 'f2', 'f3']]],
['get' => ['method' => 'GET', 'filters' => ['f1', 'f2', 'f3', 'f4']]],
[]
);
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
Expand Down Expand Up @@ -1716,6 +1730,16 @@ private function normalizeWithFilters($filterLocator)
'required' => false,
'type' => 'integer',
],
[
'name' => 'toto',
'in' => 'query',
'required' => true,
'type' => 'array',
'items' => [
'type' => 'string',
],
'collectionFormat' => 'csv',
],
[
'name' => 'page',
'in' => 'query',
Expand Down