process() public method

public process ( ContainerBuilder $container )
$container Symfony\Component\DependencyInjection\ContainerBuilder
Beispiel #1
0
 public function testOptionalScalarArgsNotPassedIfLast()
 {
     $container = new ContainerBuilder();
     $container->register('a', __NAMESPACE__ . '\\A');
     $container->register('lille', __NAMESPACE__ . '\\Lille');
     $container->register('with_optional_scalar_last', __NAMESPACE__ . '\\MultipleArgumentsOptionalScalarLast')->setAutowired(true);
     $pass = new AutowirePass();
     $pass->process($container);
     $definition = $container->getDefinition('with_optional_scalar_last');
     $this->assertEquals(array(new Reference('a'), new Reference('lille'), 'some_val'), $definition->getArguments());
 }
Beispiel #2
0
 /**
  * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
  * @expectedExceptionMessage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" for the service "setter_injection_collision". Multiple services exist for this interface (c1, c2).
  * @expectedExceptionCode 1
  */
 public function testSetterInjectionCollisionThrowsException()
 {
     $container = new ContainerBuilder();
     $container->register('c1', CollisionA::class);
     $container->register('c2', CollisionB::class);
     $aDefinition = $container->register('setter_injection_collision', SetterInjectionCollision::class);
     $aDefinition->setAutowired(true);
     $pass = new AutowirePass();
     $pass->process($container);
 }
 public function testDontUseAbstractServices()
 {
     $container = new ContainerBuilder();
     $container->register('abstract_foo', __NAMESPACE__ . '\\Foo')->setAbstract(true);
     $container->register('foo', __NAMESPACE__ . '\\Foo');
     $container->register('bar', __NAMESPACE__ . '\\Bar')->setAutowired(true);
     $pass = new AutowirePass();
     $pass->process($container);
     $arguments = $container->getDefinition('bar')->getArguments();
     $this->assertSame('foo', (string) $arguments[0]);
 }
 public function testIgnoreServiceWithClassNotExisting()
 {
     $container = new ContainerBuilder();
     $container->register('class_not_exist', __NAMESPACE__ . '\\OptionalServiceClass');
     $barDefinition = $container->register('bar', __NAMESPACE__ . '\\Bar');
     $barDefinition->setAutowired(true);
     $pass = new AutowirePass();
     $pass->process($container);
     $this->assertTrue($container->hasDefinition('bar'));
 }
Beispiel #5
0
 public function testDontTriggeruAutowiring()
 {
     $container = new ContainerBuilder();
     $container->register('foo', __NAMESPACE__ . '\\Foo');
     $container->register('bar', __NAMESPACE__ . '\\Bar');
     $pass = new AutowirePass();
     $pass->process($container);
     $this->assertCount(0, $container->getDefinition('bar')->getArguments());
 }
Beispiel #6
0
    public function testLogUnusedPatterns()
    {
        $container = new ContainerBuilder();

        $definition = $container->register('foo', Foo::class);
        $definition->setAutowiredMethods(array('not', 'exist*'));

        $pass = new AutowirePass();
        $pass->process($container);

        $this->assertEquals(array(AutowirePass::class.': Autowiring\'s patterns "not", "exist*" for service "foo" don\'t match any method.'), $container->getCompiler()->getLog());
    }