1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace phpDocumentor\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @coversDefaultClass \phpDocumentor\DependencyInjection\ReflectionProjectFactoryStrategyPass |
16
|
|
|
*/ |
17
|
|
|
final class ReflectionProjectFactoryStrategyPassTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
use ProphecyTrait; |
20
|
|
|
|
21
|
|
|
/** @covers ::process */ |
22
|
|
|
public function testTaggedStrategiesAreInjectedWithDefaultPriority() : void |
23
|
|
|
{ |
24
|
|
|
$serviceDefinition = new Definition(ProjectFactoryStrategies::class); |
25
|
|
|
|
26
|
|
|
$container = $this->prophesize(ContainerBuilder::class); |
27
|
|
|
$container->getDefinition(ProjectFactoryStrategies::class) |
28
|
|
|
->willReturn($serviceDefinition); |
29
|
|
|
|
30
|
|
|
$container->findTaggedServiceIds('phpdoc.reflection.strategy')->willReturn( |
31
|
|
|
[ |
32
|
|
|
'myStrategy' => [], |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$compilerPass = new ReflectionProjectFactoryStrategyPass(); |
37
|
|
|
|
38
|
|
|
$compilerPass->process($container->reveal()); |
39
|
|
|
|
40
|
|
|
self::assertEquals( |
41
|
|
|
[ |
42
|
|
|
[ |
43
|
|
|
'addStrategy', |
44
|
|
|
[ |
45
|
|
|
new Reference('myStrategy'), |
46
|
|
|
ProjectFactoryStrategies::DEFAULT_PRIORITY, |
47
|
|
|
], |
48
|
|
|
], |
49
|
|
|
], |
50
|
|
|
$serviceDefinition->getMethodCalls() |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @covers ::process */ |
55
|
|
|
public function testTaggedStrategiesAreInjectedWithOverwrittenPriority() : void |
56
|
|
|
{ |
57
|
|
|
$serviceDefinition = new Definition(ProjectFactoryStrategies::class); |
58
|
|
|
|
59
|
|
|
$container = $this->prophesize(ContainerBuilder::class); |
60
|
|
|
$container->getDefinition(ProjectFactoryStrategies::class) |
61
|
|
|
->willReturn($serviceDefinition); |
62
|
|
|
|
63
|
|
|
$container->findTaggedServiceIds('phpdoc.reflection.strategy')->willReturn( |
64
|
|
|
[ |
65
|
|
|
'myStrategy' => [], |
66
|
|
|
'myStrategyOther' => [ |
67
|
|
|
['priority' => 1100], |
68
|
|
|
[], |
69
|
|
|
], |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$compilerPass = new ReflectionProjectFactoryStrategyPass(); |
74
|
|
|
|
75
|
|
|
$compilerPass->process($container->reveal()); |
76
|
|
|
|
77
|
|
|
self::assertEquals( |
78
|
|
|
[ |
79
|
|
|
[ |
80
|
|
|
'addStrategy', |
81
|
|
|
[ |
82
|
|
|
new Reference('myStrategy'), |
83
|
|
|
ProjectFactoryStrategies::DEFAULT_PRIORITY, |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
[ |
87
|
|
|
'addStrategy', |
88
|
|
|
[ |
89
|
|
|
new Reference('myStrategyOther'), |
90
|
|
|
1100, |
91
|
|
|
], |
92
|
|
|
], |
93
|
|
|
], |
94
|
|
|
$serviceDefinition->getMethodCalls() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|