1
|
|
|
<?php |
2
|
|
|
namespace Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
5
|
|
|
use Doctrine\Common\Annotations\PhpParser; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap; |
8
|
|
|
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\AutowiringCompilerPass; |
9
|
|
|
use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass; |
10
|
|
|
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\AutowiredPropertyClass; |
11
|
|
|
use Skrz\Bundle\AutowiringBundle\Tests\DependencyInjection\Compiler\AutowiringCompilerPassSource\SomeClass; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
15
|
|
|
|
16
|
|
|
class AutowiringCompilerPassPropertyTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function testAutowireProperty() |
20
|
|
|
{ |
21
|
|
|
$containerBuilder = new ContainerBuilder(); |
22
|
|
|
$classMultiMap = new ClassMultiMap($containerBuilder); |
23
|
|
|
|
24
|
|
|
$classMapBuildCompilerPass = new ClassMapBuildCompilerPass($classMultiMap); |
25
|
|
|
$autowiringCompilerPass = new AutowiringCompilerPass($classMultiMap, new AnnotationReader(), new PhpParser()); |
26
|
|
|
|
27
|
|
|
$autowiredServiceDefinition = $containerBuilder->setDefinition("autowiredService", new Definition(AutowiredPropertyClass::class)); |
28
|
|
|
$containerBuilder->setDefinition("someService", new Definition(SomeClass::class)); |
29
|
|
|
|
30
|
|
|
$this->assertSame([], $autowiredServiceDefinition->getProperties()); |
31
|
|
|
|
32
|
|
|
$classMapBuildCompilerPass->process($containerBuilder); |
33
|
|
|
$autowiringCompilerPass->process($containerBuilder); |
34
|
|
|
|
35
|
|
|
$reference = $autowiredServiceDefinition->getProperties()["property"]; |
36
|
|
|
$this->assertInstanceOf(Reference::class, $reference); |
37
|
|
|
$this->assertSame("someService", (string)$reference); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
} |
41
|
|
|
|