Skip to content

Fix tests and PHPStan #3561

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

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ public function thereIsTheFollowingProduct(PyStringNode $dataNode): void
$product = $this->isOrm() ? new Product() : new ProductDocument();
$product->setCode($data['code']);
if (isset($data['mainTaxon'])) {
$mainTaxonCode = str_replace('/taxons/', '', $data['mainTaxon']);
$mainTaxonCode = str_replace('/taxa/', '', $data['mainTaxon']);
$mainTaxon = $this->manager->getRepository($this->isOrm() ? Taxon::class : TaxonDocument::class)->findOneBy([
'code' => $mainTaxonCode,
]);
Expand Down
8 changes: 4 additions & 4 deletions features/jsonld/interface_as_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Feature: JSON-LD using interface as resource
"code": "WONDERFUL_TAXON"
}
"""
When I send a "GET" request to "/taxons/WONDERFUL_TAXON"
When I send a "GET" request to "/taxa/WONDERFUL_TAXON"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/Taxon",
"@id": "/taxons/WONDERFUL_TAXON",
"@id": "/taxa/WONDERFUL_TAXON",
"@type": "Taxon",
"code": "WONDERFUL_TAXON"
}
Expand All @@ -34,7 +34,7 @@ Feature: JSON-LD using interface as resource
"""
{
"code": "GREAT_PRODUCT",
"mainTaxon": "/taxons/WONDERFUL_TAXON"
"mainTaxon": "/taxa/WONDERFUL_TAXON"
}
"""
When I send a "GET" request to "/products/GREAT_PRODUCT"
Expand All @@ -49,7 +49,7 @@ Feature: JSON-LD using interface as resource
"@type": "Product",
"code": "GREAT_PRODUCT",
"mainTaxon": {
"@id": "/taxons/WONDERFUL_TAXON",
"@id": "/taxa/WONDERFUL_TAXON",
"@type": "Taxon",
"code": "WONDERFUL_TAXON"
}
Expand Down
12 changes: 5 additions & 7 deletions src/Hydra/Serializer/CollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ public function normalize($object, $format = null, array $context = [])
$data['hydra:member'][] = $this->normalizer->normalize($obj, $format, $context);
}

$paginated = null;
if (
\is_array($object) ||
($paginated = $object instanceof PaginatorInterface) ||
$object instanceof \Countable && !$object instanceof PartialPaginatorInterface
) {
$data['hydra:totalItems'] = $paginated ? $object->getTotalItems() : \count($object);
if ($object instanceof PaginatorInterface) {
$data['hydra:totalItems'] = $object->getTotalItems();
}
if (\is_array($object) || ($object instanceof \Countable && !$object instanceof PartialPaginatorInterface)) {
$data['hydra:totalItems'] = \count($object);
}

return $data;
Expand Down
6 changes: 5 additions & 1 deletion tests/Hal/Serializer/CollectionNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public function testNormalizePartialPaginator()

private function normalizePaginator($partial = false)
{
$paginatorProphecy = $this->prophesize($partial ? PartialPaginatorInterface::class : PaginatorInterface::class);
$paginatorProphecy = $this->prophesize(PaginatorInterface::class);
if ($partial) {
$paginatorProphecy = $this->prophesize(PartialPaginatorInterface::class);
}

$paginatorProphecy->getCurrentPage()->willReturn(3);
$paginatorProphecy->getItemsPerPage()->willReturn(12);
$paginatorProphecy->rewind()->will(function () {});
Expand Down
5 changes: 4 additions & 1 deletion tests/Hydra/Serializer/CollectionNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ public function testNormalizePartialPaginator()

private function normalizePaginator($partial = false)
{
$paginatorProphecy = $this->prophesize($partial ? PartialPaginatorInterface::class : PaginatorInterface::class);
$paginatorProphecy = $this->prophesize(PaginatorInterface::class);
if ($partial) {
$paginatorProphecy = $this->prophesize(PartialPaginatorInterface::class);
}

if (!$partial) {
$paginatorProphecy->getTotalItems()->willReturn(1312);
Expand Down