|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Unit\Bundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
use Zenstruck\Foundry\Bundle\DependencyInjection\ChainManagerRegistryPass; |
|
10
|
|
|
use Zenstruck\Foundry\ChainManagerRegistry; |
|
11
|
|
|
|
|
12
|
|
|
class ChainManagerRegistryPassTest extends AbstractCompilerPassTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @test |
|
16
|
|
|
*/ |
|
17
|
|
|
public function add_both_odm_and_orm_if_present(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->setDefinition(ChainManagerRegistry::class, new Definition()); |
|
20
|
|
|
|
|
21
|
|
|
$this->setDefinition('doctrine', new Definition()); |
|
22
|
|
|
$this->setDefinition('doctrine_mongodb', new Definition()); |
|
23
|
|
|
|
|
24
|
|
|
$this->compile(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
27
|
|
|
ChainManagerRegistry::class, |
|
28
|
|
|
'$managerRegistries', |
|
29
|
|
|
[new Reference('doctrine'), new Reference('doctrine_mongodb')] |
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @test |
|
35
|
|
|
*/ |
|
36
|
|
|
public function only_add_orm(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->setDefinition(ChainManagerRegistry::class, new Definition()); |
|
39
|
|
|
|
|
40
|
|
|
$this->setDefinition('doctrine', new Definition()); |
|
41
|
|
|
|
|
42
|
|
|
$this->compile(); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
|
45
|
|
|
ChainManagerRegistry::class, |
|
46
|
|
|
'$managerRegistries', |
|
47
|
|
|
[new Reference('doctrine')] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function registerCompilerPass(ContainerBuilder $container): void |
|
52
|
|
|
{ |
|
53
|
|
|
$container->addCompilerPass(new ChainManagerRegistryPass()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|