18
18
use ApiPlatform \Core \Metadata \Resource \Factory \ResourceNameCollectionFactoryInterface ;
19
19
use ApiPlatform \Core \Metadata \Resource \ResourceNameCollection ;
20
20
use PHPUnit \Framework \TestCase ;
21
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
22
+ use Symfony \Component \HttpFoundation \Request ;
21
23
22
24
/**
23
25
* @author Amrouche Hamza <[email protected] >
@@ -26,9 +28,15 @@ class DocumentationActionTest extends TestCase
26
28
{
27
29
public function testDocumentationAction ()
28
30
{
31
+ $ requestProphecy = $ this ->prophesize (Request::class);
32
+ $ attributesProphecy = $ this ->prophesize (ParameterBagInterface::class);
29
33
$ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
30
34
$ 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 );
31
39
$ 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 () ));
33
41
}
34
42
}
0 commit comments