|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Lug package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Lug\Bundle\TranslationBundle\Tests\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Lug\Bundle\TranslationBundle\DependencyInjection\Compiler\ConfigureFactoryPass; |
|
15
|
|
|
use Lug\Component\Resource\Factory\Factory; |
|
16
|
|
|
use Lug\Component\Translation\Factory\TranslatableFactory; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author GeLo <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ConfigureFactoryPassTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ConfigureFactoryPass |
|
28
|
|
|
*/ |
|
29
|
|
|
private $compiler; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->compiler = new ConfigureFactoryPass(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testProcessWithTranslatable() |
|
40
|
|
|
{ |
|
41
|
|
|
$container = $this->createContainerBuilderMock(); |
|
42
|
|
|
$container |
|
43
|
|
|
->expects($this->once()) |
|
44
|
|
|
->method('findTaggedServiceIds') |
|
45
|
|
|
->with($this->identicalTo('lug.factory')) |
|
46
|
|
|
->will($this->returnValue([$service = 'service' => []])); |
|
47
|
|
|
|
|
48
|
|
|
$container |
|
49
|
|
|
->expects($this->once()) |
|
50
|
|
|
->method('getDefinition') |
|
51
|
|
|
->with($this->identicalTo($service)) |
|
52
|
|
|
->will($this->returnValue($factory = $this->createDefinitionMock())); |
|
53
|
|
|
|
|
54
|
|
|
$factory |
|
55
|
|
|
->expects($this->once()) |
|
56
|
|
|
->method('getClass') |
|
57
|
|
|
->will($this->returnValue(TranslatableFactory::class)); |
|
58
|
|
|
|
|
59
|
|
|
$factory |
|
60
|
|
|
->expects($this->once()) |
|
61
|
|
|
->method('addArgument') |
|
62
|
|
|
->with($this->callback(function ($argument) { |
|
63
|
|
|
return $argument instanceof Reference && (string) $argument === 'lug.translation.context.locale'; |
|
64
|
|
|
})); |
|
65
|
|
|
|
|
66
|
|
|
$this->compiler->process($container); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testProcessWithoutTranslatable() |
|
70
|
|
|
{ |
|
71
|
|
|
$container = $this->createContainerBuilderMock(); |
|
72
|
|
|
$container |
|
73
|
|
|
->expects($this->once()) |
|
74
|
|
|
->method('findTaggedServiceIds') |
|
75
|
|
|
->with($this->identicalTo('lug.factory')) |
|
76
|
|
|
->will($this->returnValue([$service = 'service' => []])); |
|
77
|
|
|
|
|
78
|
|
|
$container |
|
79
|
|
|
->expects($this->once()) |
|
80
|
|
|
->method('getDefinition') |
|
81
|
|
|
->with($this->identicalTo($service)) |
|
82
|
|
|
->will($this->returnValue($factory = $this->createDefinitionMock())); |
|
83
|
|
|
|
|
84
|
|
|
$factory |
|
85
|
|
|
->expects($this->once()) |
|
86
|
|
|
->method('getClass') |
|
87
|
|
|
->will($this->returnValue(Factory::class)); |
|
88
|
|
|
|
|
89
|
|
|
$factory |
|
90
|
|
|
->expects($this->never()) |
|
91
|
|
|
->method('addArgument'); |
|
92
|
|
|
|
|
93
|
|
|
$this->compiler->process($container); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder |
|
98
|
|
|
*/ |
|
99
|
|
|
private function createContainerBuilderMock() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->createMock(ContainerBuilder::class); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Definition |
|
106
|
|
|
*/ |
|
107
|
|
|
private function createDefinitionMock() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->createMock(Definition::class); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|