|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\Tests\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\DependencyInjection\Compiler\DoctrineMiddlewarePass; |
|
6
|
|
|
use League\Tactician\Doctrine\ORM\TransactionMiddleware; |
|
7
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
class DoctrineMiddlewarePassTest extends AbstractCompilerPassTestCase |
|
12
|
|
|
{ |
|
13
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
14
|
|
|
{ |
|
15
|
|
|
$container->addCompilerPass(new DoctrineMiddlewarePass()); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function test_registering_middleware_for_multiple_entity_managers() |
|
19
|
|
|
{ |
|
20
|
|
|
if (!class_exists(TransactionMiddleware::class)) { |
|
21
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$this->setParameter( |
|
25
|
|
|
'doctrine.entity_managers', |
|
26
|
|
|
[ |
|
27
|
|
|
'default' => 'doctrine.orm.default_entity_manager', |
|
28
|
|
|
'second' => 'doctrine.orm.second_entity_manager', |
|
29
|
|
|
] |
|
30
|
|
|
); |
|
31
|
|
|
$this->setParameter('doctrine.default_entity_manager', 'default'); |
|
32
|
|
|
|
|
33
|
|
|
$this->compile(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.default', 0, new Reference('doctrine.orm.default_entity_manager')); |
|
36
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.second', 0, new Reference('doctrine.orm.second_entity_manager')); |
|
37
|
|
|
$this->assertContainerBuilderHasAlias('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function test_do_not_process_when_there_are_no_entity_managers() |
|
41
|
|
|
{ |
|
42
|
|
|
if (!class_exists(TransactionMiddleware::class)) { |
|
43
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->compile(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertEmpty($this->container->getDefinitions()); |
|
49
|
|
|
$this->assertEmpty($this->container->getAliases()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function test_do_not_process_when_tactician_doctrine_is_not_installed() |
|
53
|
|
|
{ |
|
54
|
|
|
if (class_exists(TransactionMiddleware::class)) { |
|
55
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is installed'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->setParameter('doctrine.entity_managers', ['default' => 'doctrine.orm.default_entity_manager']); |
|
59
|
|
|
$this->setParameter('doctrine.default_entity_manager', 'default'); |
|
60
|
|
|
|
|
61
|
|
|
$this->compile(); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEmpty($this->container->getDefinitions()); |
|
64
|
|
|
$this->assertEmpty($this->container->getAliases()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|