1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ResourceBundle\Tests\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Kamil Kokot <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class DoctrineTargetEntitiesResolverPassTest extends AbstractCompilerPassTestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @test |
26
|
|
|
*/ |
27
|
|
|
public function it_adds_method_call_to_resolve_doctrine_target_entities_with_interface_given_as_fqcn() |
28
|
|
|
{ |
29
|
|
|
$this->setDefinition('doctrine.orm.listeners.resolve_target_entity', new Definition()); |
30
|
|
|
|
31
|
|
|
$this->setParameter( |
32
|
|
|
'sylius.resources', |
33
|
|
|
['app.loremipsum' => ['classes' => ['interface' => \Countable::class]]] |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$this->setParameter('app.model.loremipsum.class', \stdClass::class); |
37
|
|
|
|
38
|
|
|
$this->compile(); |
39
|
|
|
|
40
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
41
|
|
|
'doctrine.orm.listeners.resolve_target_entity', |
42
|
|
|
'addResolveTargetEntity', |
43
|
|
|
[\Countable::class, \stdClass::class, []] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @test |
49
|
|
|
*/ |
50
|
|
|
public function it_adds_method_call_to_resolve_doctrine_target_entities_with_interface_given_as_parameter() |
51
|
|
|
{ |
52
|
|
|
$this->setDefinition('doctrine.orm.listeners.resolve_target_entity', new Definition()); |
53
|
|
|
|
54
|
|
|
$this->setParameter( |
55
|
|
|
'sylius.resources', |
56
|
|
|
['app.loremipsum' => ['classes' => ['interface' => 'app.interface.loremipsum.class']]] |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->setParameter('app.model.loremipsum.class', \stdClass::class); |
60
|
|
|
$this->setParameter('app.interface.loremipsum.class', \Countable::class); |
61
|
|
|
|
62
|
|
|
$this->compile(); |
63
|
|
|
|
64
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
65
|
|
|
'doctrine.orm.listeners.resolve_target_entity', |
66
|
|
|
'addResolveTargetEntity', |
67
|
|
|
[\Countable::class, \stdClass::class, []] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @test |
73
|
|
|
*/ |
74
|
|
|
public function it_ignores_resources_without_interface() |
75
|
|
|
{ |
76
|
|
|
$this->setDefinition('doctrine.orm.listeners.resolve_target_entity', new Definition()); |
77
|
|
|
|
78
|
|
|
$this->setParameter( |
79
|
|
|
'sylius.resources', |
80
|
|
|
['app.loremipsum' => ['classes' => ['model' => \stdClass::class]]] |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->compile(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function it_adds_doctrine_event_listener_tag_to_target_entities_resolver_if_not_exists() |
90
|
|
|
{ |
91
|
|
|
$this->setDefinition('doctrine.orm.listeners.resolve_target_entity', new Definition()); |
92
|
|
|
$this->setParameter('sylius.resources', []); |
93
|
|
|
|
94
|
|
|
$this->compile(); |
95
|
|
|
|
96
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag( |
97
|
|
|
'doctrine.orm.listeners.resolve_target_entity', |
98
|
|
|
'doctrine.event_listener', |
99
|
|
|
['event' => 'loadClassMetadata'] |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
107
|
|
|
{ |
108
|
|
|
$container->addCompilerPass(new DoctrineTargetEntitiesResolverPass()); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|