1818use ApiPlatform \Core \Metadata \Resource \Factory \ResourceNameCollectionFactoryInterface ;
1919use ApiPlatform \Core \Metadata \Resource \ResourceNameCollection ;
2020use PHPUnit \Framework \TestCase ;
21+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
22+ use Symfony \Component \HttpFoundation \Request ;
2123
2224/**
2325 * @author Amrouche Hamza <hamza.simperfit@gmail.com>
@@ -26,9 +28,15 @@ class DocumentationActionTest extends TestCase
2628{
2729 public function testDocumentationAction ()
2830 {
31+ $ requestProphecy = $ this ->prophesize (Request::class);
32+ $ attributesProphecy = $ this ->prophesize (ParameterBagInterface::class);
2933 $ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
3034 $ resourceNameCollectionFactoryProphecy ->create ()->willReturn (new ResourceNameCollection (['dummies ' ]));
35+ $ requestProphecy ->attributes = $ attributesProphecy ->reveal ();
36+ $ requestProphecy ->getBaseUrl ()->willReturn ('/api ' )->shouldBeCalledTimes (1 );
37+ $ attributesProphecy ->get ('_api_normalization_context ' , [])->willReturn (['foo ' => 'bar ' ])->shouldBeCalledTimes (1 );
38+ $ attributesProphecy ->set ('_api_normalization_context ' , ['foo ' => 'bar ' , 'base_url ' => '/api ' ])->shouldBeCalledTimes (1 );
3139 $ documentation = new DocumentationAction ($ resourceNameCollectionFactoryProphecy ->reveal (), 'My happy hippie api ' , 'lots of chocolate ' , '1.0.0 ' , ['formats ' => ['jsonld ' => 'application/ld+json ' ]]);
32- $ this ->assertEquals (new Documentation (new ResourceNameCollection (['dummies ' ]), 'My happy hippie api ' , 'lots of chocolate ' , '1.0.0 ' , ['formats ' => ['jsonld ' => 'application/ld+json ' ]]), $ documentation ());
40+ $ this ->assertEquals (new Documentation (new ResourceNameCollection (['dummies ' ]), 'My happy hippie api ' , 'lots of chocolate ' , '1.0.0 ' , ['formats ' => ['jsonld ' => 'application/ld+json ' ]]), $ documentation ($ requestProphecy -> reveal () ));
3341 }
3442}
0 commit comments