コード例 #1
0
 public function testSkipAbstract()
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->setDefinition("someService", new Definition(self::SOME_CLASS_NAME))->setAbstract(true);
     $this->classMapBuildCompilerPass->process($containerBuilder);
     $this->assertSame([], $this->getClassMapBuildClasses());
 }
コード例 #2
0
 public function testAutowireProperty()
 {
     $containerBuilder = new ContainerBuilder();
     $autowiredServiceDefinition = $containerBuilder->setDefinition("autowiredService", new Definition("Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\AutowiredPropertyClass"));
     $containerBuilder->setDefinition("someService", new Definition("Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\SomeClass"));
     $this->assertSame([], $autowiredServiceDefinition->getProperties());
     $this->classMapBuildCompilerPass->process($containerBuilder);
     $this->autowiringCompilerPass->process($containerBuilder);
     $reference = $autowiredServiceDefinition->getProperties()["property"];
     $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference);
     $this->assertSame("someservice", (string) $reference);
 }
コード例 #3
0
 public function testAutowireConstructorWithInterfaceOptionally()
 {
     $containerBuilder = new ContainerBuilder();
     $service2Ref = new Reference('someService2');
     $autowiredServiceDefinition = $containerBuilder->setDefinition("autowiredService", new Definition("Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\OptionalAutowiredClass", ['someClass2' => $service2Ref]));
     $containerBuilder->setDefinition("someService", new Definition("Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\SomeClass"));
     $containerBuilder->setDefinition("someService2", new Definition("Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\SomeClass2"));
     $containerBuilder->getParameterBag()->add(['autowiring.preferred_services' => ["Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\Compiler\\AutowiringCompilerPassSource\\SomeInterface" => 'someService']]);
     $this->assertSame(['someClass2' => $service2Ref], $autowiredServiceDefinition->getArguments());
     $this->classMapBuildCompilerPass->process($containerBuilder);
     $this->autowiringCompilerPass->process($containerBuilder);
     $arguments = $autowiredServiceDefinition->getArguments();
     $this->assertNotSame([], $arguments);
     /** @var Reference $reference */
     $reference = $arguments[0];
     $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference);
     $this->assertSame("someservice", (string) $reference);
     $reference = $arguments[1];
     $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference);
     $this->assertSame("someservice2", (string) $reference);
 }