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
|
|
View Code Duplication |
public function testProcess() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$container = $this->createContainerBuilderMock(); |
41
|
|
|
$container |
|
|
|
|
42
|
|
|
->expects($this->once()) |
43
|
|
|
->method('getDefinition') |
44
|
|
|
->with($this->identicalTo('ivory.base64_file.form.extension')) |
45
|
|
|
->will($this->returnValue($definition = $this->createDefinitionMock())); |
46
|
|
|
|
47
|
|
|
$definition |
|
|
|
|
48
|
|
|
->expects($this->once()) |
49
|
|
|
->method('setClass') |
50
|
|
|
->with($this->identicalTo(Base64FileExtension::class)) |
51
|
|
|
->will($this->returnSelf()); |
52
|
|
|
|
53
|
|
|
$definition |
54
|
|
|
->expects($this->once()) |
55
|
|
|
->method('addArgument') |
56
|
|
|
->with($this->callback(function ($reference) { |
57
|
|
|
return $reference instanceof Reference |
58
|
|
|
&& (string) $reference === 'lug.resource.routing.parameter_resolver'; |
59
|
|
|
})); |
60
|
|
|
|
61
|
|
|
$this->compiler->process($container); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder |
66
|
|
|
*/ |
67
|
|
|
private function createContainerBuilderMock() |
68
|
|
|
{ |
69
|
|
|
return $this->getMock(ContainerBuilder::class); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Definition |
74
|
|
|
*/ |
75
|
|
|
private function createDefinitionMock() |
76
|
|
|
{ |
77
|
|
|
return $this->getMock(Definition::class); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.