@@ -228,6 +228,102 @@ public function ifFactoryMethodDoesNotExistOnFactoryServiceFails()
228228 $ validator ->validate ($ definition );
229229 }
230230
231+ /**
232+ * @test
233+ */
234+ public function factoryCanBeProvidedByServiceDefinition ()
235+ {
236+ if (!method_exists ('Symfony\Component\DependencyInjection\Definition ' , 'getFactory ' )) {
237+ $ this ->markTestSkipped ('Factory can be provided by service definition since Symfony 2.6 ' );
238+ }
239+
240+ $ factoryDefinition = new Definition ('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\FactoryClass ' );
241+ $ definition = new Definition ('stdClass ' );
242+ $ definition ->setFactory (array ($ factoryDefinition , 'create ' ));
243+
244+ $ containerBuilder = new ContainerBuilder ();
245+ $ validator = new ServiceDefinitionValidator (
246+ $ containerBuilder ,
247+ $ this ->createMockDefinitionArgumentsValidator (),
248+ $ this ->createMockMethodCallsValidator ()
249+ );
250+
251+ $ validator ->validate ($ definition );
252+ }
253+
254+ /**
255+ * @test
256+ */
257+ public function ifFactoryProvidedByServiceDefinitionClassDoesNotExistFails ()
258+ {
259+ if (!method_exists ('Symfony\Component\DependencyInjection\Definition ' , 'getFactory ' )) {
260+ $ this ->markTestSkipped ('Factory can be provided by service definition since Symfony 2.6 ' );
261+ }
262+
263+ $ factoryDefinition = new Definition ('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\MissingFactoryClass ' );
264+ $ definition = new Definition ('stdClass ' );
265+ $ definition ->setFactory (array ($ factoryDefinition , 'create ' ));
266+
267+ $ containerBuilder = new ContainerBuilder ();
268+ $ validator = new ServiceDefinitionValidator (
269+ $ containerBuilder ,
270+ $ this ->createMockDefinitionArgumentsValidator (),
271+ $ this ->createMockMethodCallsValidator ()
272+ );
273+
274+ $ this ->setExpectedException ('Matthias\SymfonyServiceDefinitionValidator\Exception\ClassNotFoundException ' );
275+ $ validator ->validate ($ definition );
276+ }
277+
278+ /**
279+ * @test
280+ */
281+ public function ifFactoryProvidedByServiceDefinitionSpecifiedWithoutFactoryMethodFails ()
282+ {
283+ if (!method_exists ('Symfony\Component\DependencyInjection\Definition ' , 'getFactory ' )) {
284+ $ this ->markTestSkipped ('Factory can be provided by service definition since Symfony 2.6 ' );
285+ }
286+
287+ $ factoryDefinition = new Definition ('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\FactoryClass ' );
288+ $ definition = new Definition ('stdClass ' );
289+ $ definition ->setFactory (array ($ factoryDefinition , '' ));
290+
291+ $ containerBuilder = new ContainerBuilder ();
292+ $ validator = new ServiceDefinitionValidator (
293+ $ containerBuilder ,
294+ $ this ->createMockDefinitionArgumentsValidator (),
295+ $ this ->createMockMethodCallsValidator ()
296+ );
297+
298+ $ this ->setExpectedException ('Matthias\SymfonyServiceDefinitionValidator\Exception\MissingFactoryMethodException ' );
299+ $ validator ->validate ($ definition );
300+ }
301+
302+ /**
303+ * @test
304+ */
305+ public function ifFactoryMethodDoesNotExistOnFactoryServiceProvidedByDefinitionFails ()
306+ {
307+ if (!method_exists ('Symfony\Component\DependencyInjection\Definition ' , 'getFactory ' )) {
308+ $ this ->markTestSkipped ('Factory can be provided by service definition since Symfony 2.6 ' );
309+ }
310+
311+ $ factoryDefinition = new Definition ('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\FactoryClass ' );
312+ $ definition = new Definition ('stdClass ' );
313+ $ definition ->setFactory (array ($ factoryDefinition , 'nonExistingFactoryMethod ' ));
314+
315+ $ containerBuilder = new ContainerBuilder ();
316+ $ validator = new ServiceDefinitionValidator (
317+ $ containerBuilder ,
318+ $ this ->createMockDefinitionArgumentsValidator (),
319+ $ this ->createMockMethodCallsValidator ()
320+ );
321+
322+ $ this ->setExpectedException ('Matthias\SymfonyServiceDefinitionValidator\Exception\MethodNotFoundException ' );
323+ $ validator ->validate ($ definition );
324+ }
325+
326+
231327 private function getNonExistingClassName ()
232328 {
233329 return md5 (rand (1 , 999 ));
0 commit comments