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\RollbackOnlyTransactionMiddleware; |
7
|
|
|
use League\Tactician\Doctrine\ORM\TransactionMiddleware; |
8
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
9
|
|
|
use stdClass; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
12
|
|
|
|
13
|
|
|
class DoctrineMiddlewarePassTest extends AbstractCompilerPassTestCase |
14
|
|
|
{ |
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
|
19
|
|
|
$this->container->set('doctrine.orm.default_entity_manager', new stdClass()); |
20
|
|
|
$this->container->set('doctrine.orm.second_entity_manager', new stdClass()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
24
|
|
|
{ |
25
|
|
|
$container->addCompilerPass(new DoctrineMiddlewarePass()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function test_registering_middleware_for_multiple_entity_managers() |
29
|
|
|
{ |
30
|
|
|
if (!class_exists(TransactionMiddleware::class)) { |
31
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$this->setParameter( |
35
|
|
|
'doctrine.entity_managers', |
36
|
|
|
[ |
37
|
|
|
'default' => 'doctrine.orm.default_entity_manager', |
38
|
|
|
'second' => 'doctrine.orm.second_entity_manager', |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
$this->setParameter('doctrine.default_entity_manager', 'default'); |
42
|
|
|
|
43
|
|
|
$this->compile(); |
44
|
|
|
|
45
|
|
|
$this->assertContainerBuilderHasService('tactician.middleware.doctrine.default', TransactionMiddleware::class); |
46
|
|
|
$this->assertContainerBuilderHasService('tactician.middleware.doctrine.second', TransactionMiddleware::class); |
47
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.default', 0, new Reference('doctrine.orm.default_entity_manager')); |
48
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.second', 0, new Reference('doctrine.orm.second_entity_manager')); |
49
|
|
|
$this->assertContainerBuilderHasAlias('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function test_do_not_process_when_there_are_no_entity_managers() |
53
|
|
|
{ |
54
|
|
|
if (!class_exists(TransactionMiddleware::class)) { |
55
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->compile(); |
59
|
|
|
|
60
|
|
|
$this->assertContainerBuilderNotHasService('tactician.middleware.doctrine'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function test_do_not_process_when_tactician_doctrine_is_not_installed() |
64
|
|
|
{ |
65
|
|
|
if (class_exists(TransactionMiddleware::class)) { |
66
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is installed'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->setParameter('doctrine.entity_managers', ['default' => 'doctrine.orm.default_entity_manager']); |
70
|
|
|
$this->setParameter('doctrine.default_entity_manager', 'default'); |
71
|
|
|
|
72
|
|
|
$this->compile(); |
73
|
|
|
|
74
|
|
|
$this->assertContainerBuilderNotHasService('tactician.middleware.doctrine'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function test_rollback_only_middleware_is_added() |
78
|
|
|
{ |
79
|
|
|
if (!class_exists(RollbackOnlyTransactionMiddleware::class)) { |
80
|
|
|
$this->markTestSkipped('"league/tactician-doctrine" is not installed'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->setParameter( |
84
|
|
|
'doctrine.entity_managers', |
85
|
|
|
[ |
86
|
|
|
'default' => 'doctrine.orm.default_entity_manager', |
87
|
|
|
'second' => 'doctrine.orm.second_entity_manager', |
88
|
|
|
] |
89
|
|
|
); |
90
|
|
|
$this->setParameter('doctrine.default_entity_manager', 'default'); |
91
|
|
|
|
92
|
|
|
$this->compile(); |
93
|
|
|
|
94
|
|
|
$this->assertContainerBuilderHasService('tactician.middleware.doctrine_rollback_only.default', RollbackOnlyTransactionMiddleware::class); |
95
|
|
|
$this->assertContainerBuilderHasService('tactician.middleware.doctrine_rollback_only.second', RollbackOnlyTransactionMiddleware::class); |
96
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine_rollback_only.default', 0, new Reference('doctrine.orm.default_entity_manager')); |
97
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine_rollback_only.second', 0, new Reference('doctrine.orm.second_entity_manager')); |
98
|
|
|
$this->assertContainerBuilderHasAlias('tactician.middleware.doctrine_rollback_only', 'tactician.middleware.doctrine_rollback_only.default'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|