GetHiddenValueHtmlTraitTest::testIncluded()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
namespace FwlibTest\Html\Generator\Helper;
3
4
use Fwlib\Html\Generator\Helper\GetHiddenValueHtmlTrait;
5
use Fwolf\Wrapper\PHPUnit\Helper\BuildEasyMockTrait;
6
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase;
7
use PHPUnit_Framework_MockObject_MockObject as MockObject;
8
9
/**
10
 * @copyright   Copyright 2015 Fwolf
11
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
12
 */
13
class GetHiddenValueHtmlTraitTest extends PHPUnitTestCase
14
{
15
    use BuildEasyMockTrait;
16
17
18
    /**
19
     * @param   string[] $methods
20
     * @return  MockObject|GetHiddenValueHtmlTrait
21
     */
22
    protected function buildMock(array $methods = null)
23
    {
24
        $mock = $this->getMockBuilder(GetHiddenValueHtmlTrait::class)
25
            ->setMethods($methods)
26
            ->getMockForTrait();
27
28
        return $mock;
29
    }
30
31
32 View Code Duplication
    public function testIncluded()
0 ignored issues
show
Duplication introduced by
This method 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...
33
    {
34
        $trait = $this->buildEasyMock(GetHiddenValueHtmlTrait::class, [
35
            'getName'  => 'NAME',
36
            'getValue' => 'VALUE',
37
        ]);
38
39
        $expectedOutput = <<<TAG
40
<input type='hidden'
41
  name='NAME' value='VALUE' />
42
TAG;
43
        $this->assertEquals(
44
            $expectedOutput,
45
            $this->reflectionCall($trait, 'getHiddenValueHtml')
46
        );
47
    }
48
49
50 View Code Duplication
    public function testNotIncluded()
0 ignored issues
show
Duplication introduced by
This method 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...
51
    {
52
        $trait = $this->buildEasyMock(GetHiddenValueHtmlTrait::class, [
0 ignored issues
show
Documentation introduced by
array('getName' => 'NAME...alueIncluded' => false) is of type array<string,string|fals...alueIncluded":"false"}>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
            'getName'               => 'NAME',
54
            'getValue'              => 'VALUE',
55
            'isHiddenValueIncluded' => false,
56
        ]);
57
58
        $this->assertEmpty($this->reflectionCall($trait, 'getHiddenValueHtml'));
59
    }
60
}
61