Skip to content

Commit 5b2a6f0

Browse files
committed
Self referencing subresources
1 parent 894067b commit 5b2a6f0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/Operation/Factory/SubresourceOperationFactoryTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,49 @@ public function testCreateWithMaxDepthMultipleSubresourcesSameMaxDepth()
462462
], $subresourceOperationFactory->create(DummyEntity::class));
463463
}
464464

465+
public function testCreateWithMaxDepthSelfReferencingSubresources()
466+
{
467+
/**
468+
* DummyEntity -subresource-> DummyEntity -subresource-> DummyEntity ...
469+
*/
470+
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
471+
$resourceMetadataFactoryProphecy->create(DummyEntity::class)->shouldBeCalled()->willReturn(new ResourceMetadata('dummyEntity'));
472+
473+
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
474+
$propertyNameCollectionFactoryProphecy->create(DummyEntity::class)->shouldBeCalled()->willReturn(new PropertyNameCollection(['subresource']));
475+
476+
$subresource = (new PropertyMetadata())->withSubresource(new SubresourceMetadata(DummyEntity::class, false));
477+
478+
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
479+
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'subresource')->shouldBeCalled()->willReturn($subresource);
480+
481+
$pathSegmentNameGeneratorProphecy = $this->prophesize(PathSegmentNameGeneratorInterface::class);
482+
$pathSegmentNameGeneratorProphecy->getSegmentName('dummyEntity', true)->shouldBeCalled()->willReturn('dummy_entities');
483+
$pathSegmentNameGeneratorProphecy->getSegmentName('subresource', false)->shouldBeCalled()->willReturn('subresources');
484+
485+
$subresourceOperationFactory = new SubresourceOperationFactory(
486+
$resourceMetadataFactoryProphecy->reveal(),
487+
$propertyNameCollectionFactoryProphecy->reveal(),
488+
$propertyMetadataFactoryProphecy->reveal(),
489+
$pathSegmentNameGeneratorProphecy->reveal()
490+
);
491+
492+
$this->assertEquals([
493+
'api_dummy_entities_subresource_get_subresource' => [
494+
'property' => 'subresource',
495+
'collection' => false,
496+
'resource_class' => DummyEntity::class,
497+
'shortNames' => ['dummyEntity'],
498+
'identifiers' => [
499+
['id', DummyEntity::class, true],
500+
],
501+
'route_name' => 'api_dummy_entities_subresource_get_subresource',
502+
'path' => '/dummy_entities/{id}/subresources.{_format}',
503+
'operation_name' => 'subresource_get_subresource',
504+
] + SubresourceOperationFactory::ROUTE_OPTIONS,
505+
], $subresourceOperationFactory->create(DummyEntity::class));
506+
}
507+
465508
public function testCreateWithEnd()
466509
{
467510
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);

0 commit comments

Comments
 (0)