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\ResourceBundle\Tests\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Lug\Bundle\ResourceBundle\DependencyInjection\Compiler\ReplaceBase64FileExtensionPass; |
15
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\Base64FileExtension; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ReplaceBase64FileExtensionPassTest extends \PHPUnit_Framework_TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ReplaceBase64FileExtensionPass |
27
|
|
|
*/ |
28
|
|
|
private $compiler; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->compiler = new ReplaceBase64FileExtensionPass(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testProcessWithService() |
39
|
|
|
{ |
40
|
|
|
$container = $this->createContainerBuilderMock(); |
41
|
|
|
$container |
|
|
|
|
42
|
|
|
->expects($this->once()) |
43
|
|
|
->method('hasDefinition') |
44
|
|
|
->with($this->identicalTo($service = 'ivory.base64_file.form.extension')) |
45
|
|
|
->will($this->returnValue(true)); |
46
|
|
|
|
47
|
|
|
$container |
48
|
|
|
->expects($this->once()) |
49
|
|
|
->method('getDefinition') |
50
|
|
|
->with($this->identicalTo($service)) |
51
|
|
|
->will($this->returnValue($definition = $this->createDefinitionMock())); |
52
|
|
|
|
53
|
|
|
$definition |
|
|
|
|
54
|
|
|
->expects($this->once()) |
55
|
|
|
->method('setClass') |
56
|
|
|
->with($this->identicalTo(Base64FileExtension::class)) |
57
|
|
|
->will($this->returnSelf()); |
58
|
|
|
|
59
|
|
|
$definition |
60
|
|
|
->expects($this->once()) |
61
|
|
|
->method('addArgument') |
62
|
|
|
->with($this->callback(function ($reference) { |
63
|
|
|
return $reference instanceof Reference |
64
|
|
|
&& (string) $reference === 'lug.resource.routing.parameter_resolver'; |
65
|
|
|
})); |
66
|
|
|
|
67
|
|
|
$this->compiler->process($container); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testProcessWithoutService() |
71
|
|
|
{ |
72
|
|
|
$container = $this->createContainerBuilderMock(); |
73
|
|
|
$container |
|
|
|
|
74
|
|
|
->expects($this->once()) |
75
|
|
|
->method('hasDefinition') |
76
|
|
|
->with($this->identicalTo($service = 'ivory.base64_file.form.extension')) |
77
|
|
|
->will($this->returnValue(false)); |
78
|
|
|
|
79
|
|
|
$container |
80
|
|
|
->expects($this->never()) |
81
|
|
|
->method('getDefinition'); |
82
|
|
|
|
83
|
|
|
$this->compiler->process($container); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder |
88
|
|
|
*/ |
89
|
|
|
private function createContainerBuilderMock() |
90
|
|
|
{ |
91
|
|
|
return $this->getMock(ContainerBuilder::class); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Definition |
96
|
|
|
*/ |
97
|
|
|
private function createDefinitionMock() |
98
|
|
|
{ |
99
|
|
|
return $this->getMock(Definition::class); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: