Completed
Pull Request — master (#34)
by Eric
10:19
created

Base64FileExtensionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
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
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createParameterResolverMock() can also be of type object<Lug\Bundle\Resour...meterResolverInterface>. However, the property $parameterResolver is declared as type object<PHPUnit_Framework_MockObject_MockObject>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
71
    }
72
}
73