@@ -607,4 +607,49 @@ public function testCreateWithEndButNoCollection()
607
607
] + SubresourceOperationFactory::ROUTE_OPTIONS ,
608
608
], $ result );
609
609
}
610
+
611
+ public function testCreateWithRootResourcePrefix ()
612
+ {
613
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
614
+ $ resourceMetadataFactoryProphecy ->create (RelatedDummyEntity::class)->shouldBeCalled ()->willReturn (new ResourceMetadata ('relatedDummyEntity ' ));
615
+ $ resourceMetadataFactoryProphecy ->create (DummyEntity::class)->shouldBeCalled ()->willReturn (new ResourceMetadata ('dummyEntity ' , null , null , null , null , ['route_prefix ' => 'root_resource_prefix ' ]));
616
+
617
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
618
+ $ propertyNameCollectionFactoryProphecy ->create (DummyEntity::class)->shouldBeCalled ()->willReturn (new PropertyNameCollection (['subresource ' ]));
619
+ $ propertyNameCollectionFactoryProphecy ->create (RelatedDummyEntity::class)->shouldBeCalled ()->willReturn (new PropertyNameCollection (['bar ' , 'anotherSubresource ' ]));
620
+
621
+ $ subresourceMetadataCollectionWithMaxDepth = (new PropertyMetadata ())->withSubresource (new SubresourceMetadata (RelatedDummyEntity::class, false , 1 ));
622
+ $ anotherSubresourceMetadata = (new PropertyMetadata ())->withSubresource (new SubresourceMetadata (DummyEntity::class, false ));
623
+
624
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
625
+ $ propertyMetadataFactoryProphecy ->create (DummyEntity::class, 'subresource ' )->shouldBeCalled ()->willReturn ($ subresourceMetadataCollectionWithMaxDepth );
626
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummyEntity::class, 'bar ' )->shouldBeCalled ()->willReturn (new PropertyMetadata ());
627
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummyEntity::class, 'anotherSubresource ' )->shouldBeCalled ()->willReturn ($ anotherSubresourceMetadata );
628
+
629
+ $ pathSegmentNameGeneratorProphecy = $ this ->prophesize (PathSegmentNameGeneratorInterface::class);
630
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('dummyEntity ' , true )->shouldBeCalled ()->willReturn ('dummy_entities ' );
631
+ $ pathSegmentNameGeneratorProphecy ->getSegmentName ('subresource ' , false )->shouldBeCalled ()->willReturn ('subresource ' );
632
+
633
+ $ subresourceOperationFactory = new SubresourceOperationFactory (
634
+ $ resourceMetadataFactoryProphecy ->reveal (),
635
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
636
+ $ propertyMetadataFactoryProphecy ->reveal (),
637
+ $ pathSegmentNameGeneratorProphecy ->reveal ()
638
+ );
639
+
640
+ $ this ->assertEquals ([
641
+ 'api_dummy_entities_subresource_get_subresource ' => [
642
+ 'property ' => 'subresource ' ,
643
+ 'collection ' => false ,
644
+ 'resource_class ' => RelatedDummyEntity::class,
645
+ 'shortNames ' => ['relatedDummyEntity ' , 'dummyEntity ' ],
646
+ 'identifiers ' => [
647
+ ['id ' , DummyEntity::class, true ],
648
+ ],
649
+ 'route_name ' => 'api_dummy_entities_subresource_get_subresource ' ,
650
+ 'path ' => '/root_resource_prefix/dummy_entities/{id}/subresource.{_format} ' ,
651
+ 'operation_name ' => 'subresource_get_subresource ' ,
652
+ ] + SubresourceOperationFactory::ROUTE_OPTIONS ,
653
+ ], $ subresourceOperationFactory ->create (DummyEntity::class));
654
+ }
610
655
}
0 commit comments