1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Psr\Log\LoggerInterface; |
9
|
|
|
use Psr\Log\NullLogger; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProvider; |
13
|
|
|
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProviderOverride; |
14
|
|
|
use TheCodingMachine\Interop\ServiceProviderBridgeBundle\Tests\Fixtures\TestServiceProviderOverride2; |
15
|
|
|
|
16
|
|
|
class ServiceProviderCompilationPassTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
protected function getContainer(array $lazyArray, $useDiscovery = false) |
19
|
|
|
{ |
20
|
|
|
$bundle = new InteropServiceProviderBridgeBundle($lazyArray, $useDiscovery); |
21
|
|
|
|
22
|
|
|
$container = new ContainerBuilder(); |
23
|
|
|
$container->setParameter('database_host', 'localhost'); |
24
|
|
|
$container->setDefinition('logger', (new Definition(NullLogger::class))->setPublic(true)); |
25
|
|
|
|
26
|
|
|
$bundle->build($container); |
27
|
|
|
$container->compile(); |
28
|
|
|
$bundle->setContainer($container); |
29
|
|
|
$bundle->boot(); |
30
|
|
|
return $container; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testSimpleServiceProvider() |
34
|
|
|
{ |
35
|
|
|
$container = $this->getContainer([ |
36
|
|
|
TestServiceProvider::class |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$serviceA = $container->get('serviceA'); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(\stdClass::class, $serviceA); |
42
|
|
|
$this->assertEquals(42, $container->get('function')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testServiceProviderOverrides() |
46
|
|
|
{ |
47
|
|
|
$container = $this->getContainer([ |
48
|
|
|
TestServiceProvider::class, |
49
|
|
|
TestServiceProviderOverride::class, |
50
|
|
|
TestServiceProviderOverride2::class |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$serviceA = $container->get('serviceA'); |
54
|
|
|
|
55
|
|
|
$this->assertInstanceOf(\stdClass::class, $serviceA); |
56
|
|
|
$this->assertEquals('foo', $serviceA->newProperty); |
57
|
|
|
$this->assertEquals('bar', $serviceA->newProperty2); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testExtensionsAreCalledInCorrectOrder() |
61
|
|
|
{ |
62
|
|
|
$container = $this->getContainer([ |
63
|
|
|
new TestServiceProvider(), |
64
|
|
|
new TestServiceProviderOverride(), |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
$value = $container->get('stringValue'); |
68
|
|
|
|
69
|
|
|
$this->assertSame('foo12', $value); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\InvalidArgumentException |
74
|
|
|
*/ |
75
|
|
|
/*public function testExceptionMessageIfNoPuliBundle() |
76
|
|
|
{ |
77
|
|
|
$bundle = new InteropServiceProviderBridgeBundle([], true); |
78
|
|
|
$container = new ContainerBuilder(); |
79
|
|
|
$bundle->build($container); |
80
|
|
|
$container->compile(); |
81
|
|
|
}*/ |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* |
85
|
|
|
*/ |
86
|
|
|
public function testTcmDiscovery() |
87
|
|
|
{ |
88
|
|
|
// If TCM discovery is enabled, the CommonAliasesServiceProvider is registered. |
89
|
|
|
$container = $this->getContainer([], true); |
90
|
|
|
|
91
|
|
|
$logger = $container->get(LoggerInterface::class); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $logger); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|