1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-task library. |
5
|
|
|
* |
6
|
|
|
* (c) php-task |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Task\TaskBundle\Unit\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
16
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
17
|
|
|
use Task\TaskBundle\DependencyInjection\HandlerCompilerPass; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Tests for class HandlerCompilerPass. |
21
|
|
|
*/ |
22
|
|
|
class HandlerCompilerPassTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
public function testProcess() |
25
|
|
|
{ |
26
|
|
|
$container = $this->prophesize(ContainerBuilder::class); |
27
|
|
|
|
28
|
|
|
$container->has(HandlerCompilerPass::REGISTRY_ID)->willReturn(true); |
29
|
|
|
$container->findTaggedServiceIds(HandlerCompilerPass::HANDLER_TAG)->willReturn( |
30
|
|
|
['service1' => [], 'service2' => []] |
31
|
|
|
); |
32
|
|
|
$container->getDefinition('service1')->willReturn(new Definition(\stdClass::class)); |
33
|
|
|
$container->getDefinition('service2')->willReturn(new Definition(self::class)); |
34
|
|
|
|
35
|
|
|
$serviceDefinition = $this->prophesize(Definition::class); |
36
|
|
|
$container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition); |
37
|
|
|
|
38
|
|
|
$compilerPass = new HandlerCompilerPass(); |
39
|
|
|
$compilerPass->process($container->reveal()); |
40
|
|
|
|
41
|
|
|
$serviceDefinition->replaceArgument( |
42
|
|
|
0, |
43
|
|
|
[\stdClass::class => new Reference('service1'), self::class => new Reference('service2')] |
44
|
|
|
)->shouldBeCalled(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testProcessNoTaggedService() |
48
|
|
|
{ |
49
|
|
|
$container = $this->prophesize(ContainerBuilder::class); |
50
|
|
|
|
51
|
|
|
$container->has(HandlerCompilerPass::REGISTRY_ID)->willReturn(true); |
52
|
|
|
$container->findTaggedServiceIds(HandlerCompilerPass::HANDLER_TAG)->willReturn([]); |
53
|
|
|
|
54
|
|
|
$serviceDefinition = $this->prophesize(Definition::class); |
55
|
|
|
$container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition); |
56
|
|
|
|
57
|
|
|
$compilerPass = new HandlerCompilerPass(); |
58
|
|
|
$compilerPass->process($container->reveal()); |
59
|
|
|
|
60
|
|
|
$serviceDefinition->replaceArgument(0, [])->shouldBeCalled(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|