ListViewTest::testRender()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
namespace FwlibTest\Html\ListView;
3
4
use Fwlib\Html\ListView\AbstractRetriever;
5
use Fwlib\Html\ListView\FitMode;
6
use Fwlib\Html\ListView\Fitter;
7
use Fwlib\Html\ListView\ListDto;
8
use Fwlib\Html\ListView\ListView;
9
use Fwlib\Html\ListView\Renderer;
10
use Fwlib\Html\ListView\RendererInterface;
11
use Fwlib\Html\ListView\RequestInterface;
12
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase;
13
use PHPUnit_Framework_MockObject_MockObject as MockObject;
14
15
/**
16
 * @copyright   Copyright 2015 Fwolf
17
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
18
 */
19
class ListViewTest extends PHPUnitTestCase
20
{
21
    /**
22
     * @param   string[] $methods
23
     * @return  MockObject|ListView
24
     */
25
    protected function buildMock(array $methods = null)
26
    {
27
        $mock = $this->getMock(ListView::class, $methods);
28
29
        return $mock;
30
    }
31
32
33
    public function testAccessors()
34
    {
35
        $listView = $this->buildMock();
36
37
        $this->assertInstanceOf(
38
            RendererInterface::class,
39
            $this->reflectionCall($listView, 'getRenderer')
40
        );
41
42
        $this->assertInstanceOf(
43
            RequestInterface::class,
44
            $this->reflectionCall($listView, 'getRequest')
45
        );
46
47
        /** @var MockObject|Fitter $fitter */
48
        $fitter = $this->getMock(Fitter::class, []);
49
        $listView->setFitter($fitter);
0 ignored issues
show
Bug introduced by
The method setFitter does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50
51
        $listView->setRowCount(42);
0 ignored issues
show
Bug introduced by
The method setRowCount does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
    }
53
54
55
    public function testDecorateRows()
56
    {
57
        $listView = $this->buildMock();
58
59
        $listDto = new ListDto;
60
        $this->reflectionCall($listView, 'decorateRows', [$listDto]);
61
        $this->assertEmpty($listDto->getBody());
62
63
        // No decorator
64
        $listDto->setBody([3 => ['a', 'b']])
0 ignored issues
show
Documentation introduced by
array(3 => array('a', 'b')) is of type array<integer,array<inte...",\"1\":\"string\"}>"}>, but the function expects a array<integer,object<array>>.

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...
65
            ->setRowCount(1);
66
        $this->reflectionCall($listView, 'decorateRows', [$listDto]);
67
        $this->assertEqualArray([3 => ['a', 'b']], $listDto->getBody());
68
69
        $listView->setRowDecorator(function ($row) {
0 ignored issues
show
Bug introduced by
The method setRowDecorator does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
70
            foreach ($row as &$val) {
71
                $val = strtoupper($val);
72
            }
73
            unset($val);
74
75
            return $row;
76
        });
77
        $this->reflectionCall($listView, 'decorateRows', [$listDto]);
78
        $this->assertEqualArray([3 => ['A', 'B']], $listDto->getBody());
79
    }
80
81
82
    public function testFitHeadAndBody()
83
    {
84
        $listView = $this->buildMock();
85
86
        $listView->setConfig('fitMode', FitMode::TO_TITLE);
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
        $listView->setConfig('fitEmptyFiller', '-');
88
89
        $listView->setHead(['F' => 'Foo', 'B' => 'Bar']);
0 ignored issues
show
Bug introduced by
The method setHead does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
90
        $listView->setBody([['F' => 'foo']]);
0 ignored issues
show
Bug introduced by
The method setBody does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
92
        $listDto = $this->reflectionCall($listView, 'getListDto');
93
        $this->reflectionCall($listView, 'fitHeadAndBody', [$listDto]);
94
95
        $this->assertEqualArray(
96
            [['F' => 'foo', 'B' => '-']],
97
            $listDto->getBody()
98
        );
99
    }
100
101
102 View Code Duplication
    public function testGetFilledListDto()
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...
103
    {
104
        $listView = $this->buildMock();
105
106
        /** @var MockObject|AbstractRetriever $retriever */
107
        $retriever = $this->getMock(
108
            AbstractRetriever::class,
109
            ['getListBody', 'getRowCount']
110
        );
111
        $retriever->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Fwlib\Html\ListView\AbstractRetriever.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
            ->method('getRowCount')
113
            ->willReturn(42);
114
        $listView->setRetriever($retriever);
0 ignored issues
show
Bug introduced by
The method setRetriever does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
115
116
        $listDto = $this->reflectionCall($listView, 'getFilledListDto');
117
        $this->assertEquals(42, $listDto->getRowCount());
118
    }
119
120
121
    public function testGetHtml()
122
    {
123
        $listView = $this->buildMock(
124
            ['fitHeadAndBody', 'decorateRows', 'render']
125
        );
126
        $listView->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Fwlib\Html\ListView\ListView.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
            ->method('fitHeadAndBody');
128
        $listView->expects($this->once())
129
            ->method('decorateRows');
130
        $listView->expects($this->once())
131
            ->method('render');
132
133
        $listView->getHtml();
0 ignored issues
show
Bug introduced by
The method getHtml does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
134
    }
135
136
137
    public function testRender()
138
    {
139
        /** @var MockObject|Renderer $renderer */
140
        $renderer = $this->getMock(
141
            Renderer::class,
142
            ['setConfigInstance', 'setListDto', 'getHtml']
143
        );
144
        $renderer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Fwlib\Html\ListView\Renderer.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
145
            ->method('setConfigInstance')
146
            ->willReturnSelf();
147
        $renderer->expects($this->once())
148
            ->method('setListDto')
149
            ->willReturnSelf();
150
        $renderer->expects($this->once())
151
            ->method('getHtml');
152
153
        $listView = $this->buildMock();
154
        $listView->setRenderer($renderer);
0 ignored issues
show
Bug introduced by
The method setRenderer does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
155
156
        $this->reflectionCall($listView, 'render', [new ListDto()]);
157
    }
158
159
160
    public function testSetBody()
161
    {
162
        $listView = $this->buildMock();
163
164
        $listView->setBody([['key' => 'foo'], ['key' => 'bar']], true);
0 ignored issues
show
Bug introduced by
The method setBody does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
165
        /** @var ListDto $listDto */
166
        $listDto = $this->reflectionCall($listView, 'getListDto');
167
        $this->assertEquals(2, $listDto->getRowCount());
168
169
        $listView->reset();
0 ignored issues
show
Bug introduced by
The method reset does only exist in Fwlib\Html\ListView\ListView, but not in PHPUnit_Framework_MockObject_MockObject.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
        $listDto = $this->reflectionCall($listView, 'getListDto');
171
        $this->assertEquals(
172
            ListView::ROW_COUNT_NOT_SET,
173
            $listDto->getRowCount()
174
        );
175
    }
176
}
177