1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Unit\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Prophecy\Argument; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
8
|
|
|
use Task\TaskBundle\DependencyInjection\HandlerCompilerPass; |
9
|
|
|
use Task\TaskBundle\DependencyInjection\TaskCompilerPass; |
10
|
|
|
|
11
|
|
|
class TaskCompilerPassTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
public function testProcess() |
14
|
|
|
{ |
15
|
|
|
$containerBuilder = $this->prophesize(ContainerBuilder::class); |
16
|
|
|
$schedulerDefinition = $this->prophesize(Definition::class); |
17
|
|
|
$handler1Definition = $this->prophesize(Definition::class); |
18
|
|
|
$handler2Definition = $this->prophesize(Definition::class); |
19
|
|
|
|
20
|
|
|
$containerBuilder->has(TaskCompilerPass::SCHEDULER_ID)->willReturn(true); |
21
|
|
|
$containerBuilder->getDefinition(TaskCompilerPass::SCHEDULER_ID)->willReturn($schedulerDefinition->reveal()); |
22
|
|
|
$containerBuilder->getDefinition('id-1')->willReturn($handler1Definition->reveal()); |
23
|
|
|
$containerBuilder->getDefinition('id-2')->willReturn($handler2Definition->reveal()); |
24
|
|
|
|
25
|
|
|
$containerBuilder->findTaggedServiceIds(TaskCompilerPass::INTERVAL_TAG) |
26
|
|
|
->willReturn( |
27
|
|
|
[ |
28
|
|
|
'id-1' => [ |
29
|
|
|
[ |
30
|
|
|
TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
31
|
|
|
TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload', |
32
|
|
|
TaskCompilerPass::KEY_ATTRIBUTE => 'test-key' |
33
|
|
|
], |
34
|
|
|
], |
35
|
|
|
'id-2' => [ |
36
|
|
|
[ |
37
|
|
|
TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
38
|
|
|
TaskCompilerPass::KEY_ATTRIBUTE => 'test-key-1' |
39
|
|
|
], |
40
|
|
|
[ |
41
|
|
|
TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily', |
42
|
|
|
TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload-2' |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$handler1Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn( |
49
|
|
|
[[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-1']] |
50
|
|
|
); |
51
|
|
|
$handler2Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn( |
52
|
|
|
[[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-2']] |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$compilerPass = new TaskCompilerPass(); |
56
|
|
|
$compilerPass->process($containerBuilder->reveal()); |
57
|
|
|
|
58
|
|
|
$schedulerDefinition->addMethodCall( |
59
|
|
|
TaskCompilerPass::CREATE_FUNCTION_NAME, |
60
|
|
|
['handler-1', 'test-workload', 'daily', 'test-key'] |
61
|
|
|
)->shouldBeCalledTimes(1); |
62
|
|
|
$schedulerDefinition->addMethodCall( |
63
|
|
|
TaskCompilerPass::CREATE_FUNCTION_NAME, |
64
|
|
|
['handler-2', null, 'daily', 'test-key-1'] |
65
|
|
|
)->shouldBeCalledTimes(1); |
66
|
|
|
$schedulerDefinition->addMethodCall( |
67
|
|
|
TaskCompilerPass::CREATE_FUNCTION_NAME, |
68
|
|
|
['handler-2', 'test-workload-2', 'daily', 'handler-2_daily_s:15:"test-workload-2";'] |
69
|
|
|
)->shouldBeCalledTimes(1); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|