19
19
use ApiPlatform \Core \Routing \ResourcePathGeneratorInterface ;
20
20
use ApiPlatform \Core \Tests \Fixtures \DummyEntity ;
21
21
use Prophecy \Argument ;
22
+ use Symfony \Component \DependencyInjection \ContainerInterface ;
22
23
use Symfony \Component \HttpKernel \KernelInterface ;
23
24
use Symfony \Component \Routing \Route ;
24
25
25
26
/**
26
27
* @author Antoine Bluchet <soyuka@gmail.com>
28
+ * @author Amrouche Hamza <hamza.simperfit@gmail.com>
27
29
*/
28
30
class ApiLoaderTest extends \PHPUnit_Framework_TestCase
29
31
{
@@ -99,6 +101,25 @@ public function testNoMethodApiLoader()
99
101
$ routeCollection = $ this ->getApiLoaderWithResourceMetadata ($ resourceMetadata )->load (null );
100
102
}
101
103
104
+ /**
105
+ * @expectedException \RuntimeException
106
+ */
107
+ public function testWrongMethodApiLoader ()
108
+ {
109
+ $ resourceMetadata = new ResourceMetadata ();
110
+ $ resourceMetadata = $ resourceMetadata ->withShortName ('dummy ' );
111
+
112
+ $ resourceMetadata = $ resourceMetadata ->withItemOperations ([
113
+ 'post ' => ['method ' => 'POST ' ],
114
+ ]);
115
+
116
+ $ resourceMetadata = $ resourceMetadata ->withCollectionOperations ([
117
+ 'get ' => ['method ' => 'GET ' ],
118
+ ]);
119
+
120
+ $ routeCollection = $ this ->getApiLoaderWithResourceMetadata ($ resourceMetadata )->load (null );
121
+ }
122
+
102
123
/**
103
124
* @expectedException \ApiPlatform\Core\Exception\InvalidResourceException
104
125
*/
@@ -113,6 +134,20 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
113
134
114
135
$ kernelProphecy = $ this ->prophesize (KernelInterface::class);
115
136
$ kernelProphecy ->locateResource (Argument::any ())->willReturn ($ routingConfig );
137
+ $ possibleArguments = [
138
+ 'api_platform.action.get_collection ' ,
139
+ 'api_platform.action.post_collection ' ,
140
+ 'api_platform.action.get_item ' ,
141
+ 'api_platform.action.put_item ' ,
142
+ 'api_platform.action.delete_item ' ,
143
+ ];
144
+ $ containerProphecy = $ this ->prophesize (ContainerInterface::class);
145
+
146
+ foreach ($ possibleArguments as $ possibleArgument ) {
147
+ $ containerProphecy ->has ($ possibleArgument )->willReturn (true );
148
+ }
149
+
150
+ $ containerProphecy ->has (Argument::type ('string ' ))->willReturn (false );
116
151
117
152
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
118
153
$ resourceMetadataFactoryProphecy ->create (DummyEntity::class)->willReturn ($ resourceMetadata );
@@ -123,7 +158,7 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
123
158
$ resourcePathGeneratorProphecy = $ this ->prophesize (ResourcePathGeneratorInterface::class);
124
159
$ resourcePathGeneratorProphecy ->generateResourceBasePath ('dummy ' )->willReturn ('dummies ' );
125
160
126
- $ apiLoader = new ApiLoader ($ kernelProphecy ->reveal (), $ resourceNameCollectionFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), $ resourcePathGeneratorProphecy ->reveal ());
161
+ $ apiLoader = new ApiLoader ($ kernelProphecy ->reveal (), $ resourceNameCollectionFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), $ resourcePathGeneratorProphecy ->reveal (), $ containerProphecy -> reveal () );
127
162
128
163
return $ apiLoader ;
129
164
}
0 commit comments