@@ -462,6 +462,49 @@ public function testCreateWithMaxDepthMultipleSubresourcesSameMaxDepth()
462
462
], $ subresourceOperationFactory ->create (DummyEntity::class));
463
463
}
464
464
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
+
465
508
public function testCreateWithEnd ()
466
509
{
467
510
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
0 commit comments