Skip to content

Commit c037ded

Browse files
committed
sfix tests
1 parent 238fd94 commit c037ded

File tree

6 files changed

+16
-51
lines changed

6 files changed

+16
-51
lines changed

features/jsonld/input_output.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ Feature: JSON-LD DTO input and output
374374
"""
375375

376376
@v3
377-
# Cannot generate proper IRI because DTO does not support resource yet
378-
# todo Change member IRI to `/dummy_foos/bar` once DTO support resource
379377
Scenario: Get a collection with a custom output and itemUriTemplate, from a resource without identifier
380378
When I send a "GET" request to "/dummy_foo_collection_dtos"
381379
Then the response status code should be 200
@@ -401,7 +399,7 @@ Feature: JSON-LD DTO input and output
401399
"additionalProperties": false,
402400
"required": ["@id", "@type", "foo", "bar"],
403401
"properties": {
404-
"@id": {"pattern": "^/.well-known/genid/.+$"},
402+
"@id": {"pattern": "/dummy_foos/bar"},
405403
"@type": {"pattern": "^DummyCollectionDtoOutput$"},
406404
"foo": {"type": "string"},
407405
"bar": {"type": "integer"}

src/Hydra/Tests/Serializer/CollectionNormalizerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ public function testNormalizeIriOnlyResourceCollection(): void
224224

225225
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
226226
$iriConverterProphecy->getIriFromResource(Foo::class, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos');
227-
$iriConverterProphecy->getIriFromResource($fooOne)->willReturn('/foos/1');
228-
$iriConverterProphecy->getIriFromResource($fooThree)->willReturn('/foos/3');
227+
$iriConverterProphecy->getIriFromResource($fooOne, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos/1');
228+
$iriConverterProphecy->getIriFromResource($fooThree, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos/3');
229229

230230
$delegateNormalizerProphecy = $this->prophesize(NormalizerInterface::class);
231231

@@ -276,8 +276,8 @@ public function testNormalizeIriOnlyEmbedContextResourceCollection(): void
276276

277277
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
278278
$iriConverterProphecy->getIriFromResource(Foo::class, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos');
279-
$iriConverterProphecy->getIriFromResource($fooOne)->willReturn('/foos/1');
280-
$iriConverterProphecy->getIriFromResource($fooThree)->willReturn('/foos/3');
279+
$iriConverterProphecy->getIriFromResource($fooOne, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos/1');
280+
$iriConverterProphecy->getIriFromResource($fooThree, UrlGeneratorInterface::ABS_PATH, Argument::any(), Argument::any())->willReturn('/foos/3');
281281

282282
$delegateNormalizerProphecy = $this->prophesize(NormalizerInterface::class);
283283

src/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
101101
$resourceClass = $this->getObjectClass($object);
102102
$outputClass = $this->getOutputClass($context);
103103

104-
if ($outputClass && !$context['item_uri_template']) {
104+
if ($outputClass && !($context['item_uri_template'] ?? null)) {
105105
return parent::normalize($object, $format, $context);
106106
}
107107

src/Metadata/IdentifiersExtractor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
5151
public function getIdentifiersFromItem(object $item, ?Operation $operation = null, array $context = []): array
5252
{
5353
if (!$this->isResourceClass($this->getObjectClass($item))) {
54-
return ['id' => $this->propertyAccessor->getValue($item, 'id')];
54+
try {
55+
return ['id' => $this->propertyAccessor->getValue($item, 'id')];
56+
} catch (NoSuchPropertyException $e) {
57+
throw new RuntimeException('Not able to retrieve identifiers.', $e->getCode(), $e);
58+
}
5559
}
5660

5761
if ($operation && $operation->getClass()) {

src/Symfony/Routing/IriConverter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ public function getIriFromResource(object|string $resource, int $referenceType =
127127
return $this->generateSymfonyRoute($resource, $referenceType, $this->localOperationCache[$localOperationCacheKey], $context, $this->localIdentifiersExtractorOperationCache[$localOperationCacheKey] ?? null);
128128
}
129129

130-
if (!isset($context['item_uri_template']) && !$this->resourceClassResolver->isResourceClass($resourceClass)) {
130+
if (!($isResourceClass = $this->resourceClassResolver->isResourceClass($resourceClass)) && !isset($context['item_uri_template'])) {
131131
return $this->generateSkolemIri($resource, $referenceType, $operation, $context, $resourceClass);
132132
}
133133

134+
$context['is_resource_class'] = $isResourceClass;
135+
$context['current_resource_class'] = $resourceClass;
136+
134137
// This is only for when a class (that is not a resource) extends another one that is a resource, we should remove this behavior
135138
if (!\is_string($resource) && !isset($context['force_resource_class']) && !isset($context['item_uri_template'])) {
136139
$resourceClass = $this->getResourceClass($resource, true);
@@ -188,7 +191,7 @@ private function generateSymfonyRoute(object|string $resource, int $referenceTyp
188191
$identifiers = $this->identifiersExtractor->getIdentifiersFromItem($resource, $identifiersExtractorOperation, $context);
189192
} catch (InvalidArgumentException|RuntimeException $e) {
190193
// We can try using context uri variables if any
191-
if (!$identifiers) {
194+
if (!$identifiers && ($context['is_resource_class'] ?? false)) {
192195
throw new InvalidArgumentException(\sprintf('Unable to generate an IRI for the item of type "%s"', $operation->getClass()), $e->getCode(), $e);
193196
}
194197
}

tests/Fixtures/TestBundle/Document/BookStore.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)