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\Form\Extension; |
13
|
|
|
|
14
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\Base64FileExtension; |
15
|
|
|
use Lug\Bundle\ResourceBundle\Routing\ParameterResolverInterface; |
16
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType; |
17
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
18
|
|
|
use Symfony\Component\Form\Forms; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
class Base64FileExtensionTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FormFactoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $formFactory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Base64FileExtension |
32
|
|
|
*/ |
33
|
|
|
private $extension; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface |
37
|
|
|
*/ |
38
|
|
|
private $parameterResolver; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
protected function setUp() |
44
|
|
|
{ |
45
|
|
|
$this->parameterResolver = $this->createParameterResolverMock(); |
|
|
|
|
46
|
|
|
$this->extension = new Base64FileExtension($this->parameterResolver); |
47
|
|
|
|
48
|
|
|
$this->formFactory = Forms::createFormFactoryBuilder() |
49
|
|
|
->addTypeExtension($this->extension) |
50
|
|
|
->getFormFactory(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testType() |
54
|
|
|
{ |
55
|
|
|
$this->parameterResolver |
56
|
|
|
->expects($this->once()) |
57
|
|
|
->method('resolveApi') |
58
|
|
|
->will($this->returnValue(true)); |
59
|
|
|
|
60
|
|
|
$form = $this->formFactory->create(FileType::class); |
61
|
|
|
|
62
|
|
|
$this->assertTrue($form->getConfig()->getOption('base64')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface |
67
|
|
|
*/ |
68
|
|
|
private function createParameterResolverMock() |
69
|
|
|
{ |
70
|
|
|
return $this->getMock(ParameterResolverInterface::class); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.