GridExtensionTest::createPagerfantaMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\GridBundle\Tests\Twig;
13
14
use Lug\Bundle\GridBundle\Twig\GridExtension;
15
use Lug\Component\Grid\Model\ActionInterface;
16
use Lug\Component\Grid\Model\ColumnInterface;
17
use Lug\Component\Grid\Renderer\RendererInterface;
18
use Lug\Component\Grid\View\GridViewInterface;
19
use Pagerfanta\Pagerfanta;
20
use WhiteOctober\PagerfantaBundle\Twig\PagerfantaExtension;
21
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class GridExtensionTest extends \PHPUnit_Framework_TestCase
26
{
27
    /**
28
     * @var GridExtension
29
     */
30
    private $extension;
31
32
    /**
33
     * @var \PHPUnit_Framework_MockObject_MockObject|RendererInterface
34
     */
35
    private $renderer;
36
37
    /**
38
     * @var \PHPUnit_Framework_MockObject_MockObject|PagerfantaExtension
39
     */
40
    private $pagerfantaExtension;
41
42
    /**
43
     * @var \Twig_Environment
44
     */
45
    private $twig;
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    protected function setUp()
51
    {
52
        $this->renderer = $this->createRendererMock();
53
        $this->pagerfantaExtension = $this->createPagerfantaExtensionMock();
54
55
        $this->extension = new GridExtension($this->renderer, $this->pagerfantaExtension);
56
57
        $this->twig = new \Twig_Environment(new \Twig_Loader_Array([]));
58
        $this->twig->addExtension($this->extension);
59
    }
60
61
    public function testInheritance()
62
    {
63
        $this->assertInstanceOf(RendererInterface::class, $this->extension);
64
        $this->assertInstanceOf(\Twig_Extension::class, $this->extension);
65
    }
66
67
    public function testGrid()
68
    {
69
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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
            ->expects($this->once())
71
            ->method('render')
72
            ->with($this->identicalTo($grid = $this->createGridViewMock()))
73
            ->will($this->returnValue($result = '<div>result</div>'));
74
75
        $this->assertSame(
76
            $result,
77
            $this->twig->createTemplate('{{ lug_grid(grid) }}')->render(['grid' => $grid])
78
        );
79
    }
80
81
    public function testFilters()
82
    {
83
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
84
            ->expects($this->once())
85
            ->method('renderFilters')
86
            ->with($this->identicalTo($grid = $this->createGridViewMock()))
87
            ->will($this->returnValue($result = '<div>result</div>'));
88
89
        $this->assertSame(
90
            $result,
91
            $this->twig->createTemplate('{{ lug_grid_filters(grid) }}')->render(['grid' => $grid])
92
        );
93
    }
94
95
    public function testBody()
96
    {
97
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
98
            ->expects($this->once())
99
            ->method('renderGrid')
100
            ->with($this->identicalTo($grid = $this->createGridViewMock()))
101
            ->will($this->returnValue($result = '<div>result</div>'));
102
103
        $this->assertSame(
104
            $result,
105
            $this->twig->createTemplate('{{ lug_grid_body(grid) }}')->render(['grid' => $grid])
106
        );
107
    }
108
109 View Code Duplication
    public function testColumn()
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...
110
    {
111
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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
            ->expects($this->once())
113
            ->method('renderColumn')
114
            ->with(
115
                $this->identicalTo($grid = $this->createGridViewMock()),
116
                $this->identicalTo($column = $this->createColumnMock()),
117
                $this->identicalTo($data = 'data')
118
            )
119
            ->will($this->returnValue($result = '<div>result</div>'));
120
121
        $this->assertSame(
122
            $result,
123
            $this->twig
124
                ->createTemplate('{{ lug_grid_column(grid, column, data) }}')
125
                ->render(['grid' => $grid, 'column' => $column, 'data' => $data])
126
        );
127
    }
128
129
    public function testColumnActions()
130
    {
131
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
132
            ->expects($this->once())
133
            ->method('renderColumnActions')
134
            ->with(
135
                $this->identicalTo($grid = $this->createGridViewMock()),
136
                $this->identicalTo($data = 'data')
137
            )
138
            ->will($this->returnValue($result = '<div>result</div>'));
139
140
        $this->assertSame(
141
            $result,
142
            $this->twig
143
                ->createTemplate('{{ lug_grid_column_actions(grid, data) }}')
144
                ->render(['grid' => $grid, 'data' => $data])
145
        );
146
    }
147
148 View Code Duplication
    public function testColumnAction()
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...
149
    {
150
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
151
            ->expects($this->once())
152
            ->method('renderColumnAction')
153
            ->with(
154
                $this->identicalTo($grid = $this->createGridViewMock()),
155
                $this->identicalTo($action = $this->createActionMock()),
156
                $this->identicalTo($data = 'data')
157
            )
158
            ->will($this->returnValue($result = '<div>result</div>'));
159
160
        $this->assertSame(
161
            $result,
162
            $this->twig
163
                ->createTemplate('{{ lug_grid_column_action(grid, action, data) }}')
164
                ->render(['grid' => $grid, 'action' => $action, 'data' => $data])
165
        );
166
    }
167
168
    public function testColumnSortings()
169
    {
170
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
171
            ->expects($this->once())
172
            ->method('renderColumnSortings')
173
            ->with(
174
                $this->identicalTo($grid = $this->createGridViewMock()),
175
                $this->identicalTo($column = $this->createColumnMock())
176
            )
177
            ->will($this->returnValue($result = '<div>result</div>'));
178
179
        $this->assertSame(
180
            $result,
181
            $this->twig
182
                ->createTemplate('{{ lug_grid_column_sortings(grid, column) }}')
183
                ->render(['grid' => $grid, 'column' => $column])
184
        );
185
    }
186
187 View Code Duplication
    public function testColumnSorting()
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...
188
    {
189
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
190
            ->expects($this->once())
191
            ->method('renderColumnSorting')
192
            ->with(
193
                $this->identicalTo($grid = $this->createGridViewMock()),
194
                $this->identicalTo($column = $this->createColumnMock()),
195
                $this->identicalTo($sorting = 'sorting')
196
            )
197
            ->will($this->returnValue($result = '<div>result</div>'));
198
199
        $this->assertSame(
200
            $result,
201
            $this->twig
202
                ->createTemplate('{{ lug_grid_column_sorting(grid, column, sorting) }}')
203
                ->render(['grid' => $grid, 'column' => $column, 'sorting' => $sorting])
204
        );
205
    }
206
207
    public function testGlobalActions()
208
    {
209
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
210
            ->expects($this->once())
211
            ->method('renderGlobalActions')
212
            ->with($this->identicalTo($grid = $this->createGridViewMock()))
213
            ->will($this->returnValue($result = '<div>result</div>'));
214
215
        $this->assertSame(
216
            $result,
217
            $this->twig->createTemplate('{{ lug_grid_global_actions(grid) }}')->render(['grid' => $grid])
218
        );
219
    }
220
221
    public function testGlobalAction()
222
    {
223
        $this->renderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Renderer\RendererInterface.

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...
224
            ->expects($this->once())
225
            ->method('renderGlobalAction')
226
            ->with(
227
                $this->identicalTo($grid = $this->createGridViewMock()),
228
                $this->identicalTo($action = $this->createActionMock())
229
            )
230
            ->will($this->returnValue($result = '<div>result</div>'));
231
232
        $this->assertSame(
233
            $result,
234
            $this->twig
235
                ->createTemplate('{{ lug_grid_global_action(grid, action) }}')
236
                ->render(['grid' => $grid, 'action' => $action])
237
        );
238
    }
239
240 View Code Duplication
    public function testPager()
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...
241
    {
242
        $this->pagerfantaExtension
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in WhiteOctober\PagerfantaB...wig\PagerfantaExtension.

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...
243
            ->expects($this->once())
244
            ->method('renderPagerfanta')
245
            ->with(
246
                $this->identicalTo($pager = $this->createPagerfantaMock()),
247
                $this->identicalTo($name = 'name'),
248
                $this->identicalTo($options = ['foo' => 'bar'])
249
            )
250
            ->will($this->returnValue($result = '<div>result</div>'));
251
252
        $this->assertSame(
253
            $result,
254
            $this->twig
255
                ->createTemplate('{{ lug_grid_pager(pager, name, options) }}')
256
                ->render(['pager' => $pager, 'name' => $name, 'options' => $options])
257
        );
258
    }
259
260
    public function testPagerWithReset()
261
    {
262
        $this->pagerfantaExtension
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in WhiteOctober\PagerfantaB...wig\PagerfantaExtension.

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...
263
            ->expects($this->once())
264
            ->method('renderPagerfanta')
265
            ->with(
266
                $this->identicalTo($pager = $this->createPagerfantaMock()),
267
                $this->identicalTo($name = 'name'),
268
                $this->identicalTo($options = ['routeParams' => ['foo' => 'bar']])
269
            )
270
            ->will($this->returnValue($result = '<div>result</div>'));
271
272
        $options['routeParams']['grid']['baz'] = 'bat';
273
        $options['routeParams']['grid']['reset'] = true;
274
275
        $this->assertSame(
276
            $result,
277
            $this->twig
278
                ->createTemplate('{{ lug_grid_pager(pager, name, options) }}')
279
                ->render(['pager' => $pager, 'name' => $name, 'options' => $options])
280
        );
281
    }
282
283
    public function testName()
284
    {
285
        $this->assertSame('lug_grid', $this->extension->getName());
286
    }
287
288
    /**
289
     * @return \PHPUnit_Framework_MockObject_MockObject|RendererInterface
290
     */
291
    private function createRendererMock()
292
    {
293
        return $this->createMock(RendererInterface::class);
294
    }
295
296
    /**
297
     * @return \PHPUnit_Framework_MockObject_MockObject|PagerfantaExtension
298
     */
299
    private function createPagerfantaExtensionMock()
300
    {
301
        return $this->createMock(PagerfantaExtension::class);
302
    }
303
304
    /**
305
     * @return \PHPUnit_Framework_MockObject_MockObject|GridViewInterface
306
     */
307
    private function createGridViewMock()
308
    {
309
        return $this->createMock(GridViewInterface::class);
310
    }
311
312
    /**
313
     * @return \PHPUnit_Framework_MockObject_MockObject|ColumnInterface
314
     */
315
    private function createColumnMock()
316
    {
317
        return $this->createMock(ColumnInterface::class);
318
    }
319
320
    /**
321
     * @return \PHPUnit_Framework_MockObject_MockObject|ActionInterface
322
     */
323
    private function createActionMock()
324
    {
325
        return $this->createMock(ActionInterface::class);
326
    }
327
328
    /**
329
     * @return \PHPUnit_Framework_MockObject_MockObject|Pagerfanta
330
     */
331
    private function createPagerfantaMock()
332
    {
333
        return $this->createMock(Pagerfanta::class);
334
    }
335
}
336