Skip to content

Commit 563e017

Browse files
authored
Fix tests and PHPStan (#3561)
1 parent d5916f2 commit 563e017

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ public function thereIsTheFollowingProduct(PyStringNode $dataNode): void
14811481
$product = $this->isOrm() ? new Product() : new ProductDocument();
14821482
$product->setCode($data['code']);
14831483
if (isset($data['mainTaxon'])) {
1484-
$mainTaxonCode = str_replace('/taxons/', '', $data['mainTaxon']);
1484+
$mainTaxonCode = str_replace('/taxa/', '', $data['mainTaxon']);
14851485
$mainTaxon = $this->manager->getRepository($this->isOrm() ? Taxon::class : TaxonDocument::class)->findOneBy([
14861486
'code' => $mainTaxonCode,
14871487
]);

features/jsonld/interface_as_resource.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ Feature: JSON-LD using interface as resource
1515
"code": "WONDERFUL_TAXON"
1616
}
1717
"""
18-
When I send a "GET" request to "/taxons/WONDERFUL_TAXON"
18+
When I send a "GET" request to "/taxa/WONDERFUL_TAXON"
1919
Then the response status code should be 200
2020
And the response should be in JSON
2121
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
2222
And the JSON should be equal to:
2323
"""
2424
{
2525
"@context": "/contexts/Taxon",
26-
"@id": "/taxons/WONDERFUL_TAXON",
26+
"@id": "/taxa/WONDERFUL_TAXON",
2727
"@type": "Taxon",
2828
"code": "WONDERFUL_TAXON"
2929
}
@@ -34,7 +34,7 @@ Feature: JSON-LD using interface as resource
3434
"""
3535
{
3636
"code": "GREAT_PRODUCT",
37-
"mainTaxon": "/taxons/WONDERFUL_TAXON"
37+
"mainTaxon": "/taxa/WONDERFUL_TAXON"
3838
}
3939
"""
4040
When I send a "GET" request to "/products/GREAT_PRODUCT"
@@ -49,7 +49,7 @@ Feature: JSON-LD using interface as resource
4949
"@type": "Product",
5050
"code": "GREAT_PRODUCT",
5151
"mainTaxon": {
52-
"@id": "/taxons/WONDERFUL_TAXON",
52+
"@id": "/taxa/WONDERFUL_TAXON",
5353
"@type": "Taxon",
5454
"code": "WONDERFUL_TAXON"
5555
}

src/Hydra/Serializer/CollectionNormalizer.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ public function normalize($object, $format = null, array $context = [])
8787
$data['hydra:member'][] = $this->normalizer->normalize($obj, $format, $context);
8888
}
8989

90-
$paginated = null;
91-
if (
92-
\is_array($object) ||
93-
($paginated = $object instanceof PaginatorInterface) ||
94-
$object instanceof \Countable && !$object instanceof PartialPaginatorInterface
95-
) {
96-
$data['hydra:totalItems'] = $paginated ? $object->getTotalItems() : \count($object);
90+
if ($object instanceof PaginatorInterface) {
91+
$data['hydra:totalItems'] = $object->getTotalItems();
92+
}
93+
if (\is_array($object) || ($object instanceof \Countable && !$object instanceof PartialPaginatorInterface)) {
94+
$data['hydra:totalItems'] = \count($object);
9795
}
9896

9997
return $data;

tests/Hal/Serializer/CollectionNormalizerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ public function testNormalizePartialPaginator()
112112

113113
private function normalizePaginator($partial = false)
114114
{
115-
$paginatorProphecy = $this->prophesize($partial ? PartialPaginatorInterface::class : PaginatorInterface::class);
115+
$paginatorProphecy = $this->prophesize(PaginatorInterface::class);
116+
if ($partial) {
117+
$paginatorProphecy = $this->prophesize(PartialPaginatorInterface::class);
118+
}
119+
116120
$paginatorProphecy->getCurrentPage()->willReturn(3);
117121
$paginatorProphecy->getItemsPerPage()->willReturn(12);
118122
$paginatorProphecy->rewind()->will(function () {});

tests/Hydra/Serializer/CollectionNormalizerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ public function testNormalizePartialPaginator()
291291

292292
private function normalizePaginator($partial = false)
293293
{
294-
$paginatorProphecy = $this->prophesize($partial ? PartialPaginatorInterface::class : PaginatorInterface::class);
294+
$paginatorProphecy = $this->prophesize(PaginatorInterface::class);
295+
if ($partial) {
296+
$paginatorProphecy = $this->prophesize(PartialPaginatorInterface::class);
297+
}
295298

296299
if (!$partial) {
297300
$paginatorProphecy->getTotalItems()->willReturn(1312);

0 commit comments

Comments
 (0)