|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\View; |
|
4
|
|
|
|
|
5
|
|
|
use Pagerfanta\View\OptionableView; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class OptionableViewTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
private $pagerfanta; |
|
11
|
|
|
private $routeGenerator; |
|
12
|
|
|
private $rendered; |
|
13
|
|
|
|
|
14
|
|
|
protected function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->pagerfanta = $this->createPagerfantaMock(); |
|
17
|
|
|
$this->routeGenerator = $this->createRouteGenerator(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
private function createPagerfantaMock() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->getMockBuilder('Pagerfanta\PagerfantaInterface')->getMock(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function createRouteGenerator() |
|
26
|
|
|
{ |
|
27
|
|
|
return function () {}; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testRenderShouldDelegateToTheView() |
|
31
|
|
|
{ |
|
32
|
|
|
$defaultOptions = array('foo' => 'bar', 'bar' => 'ups'); |
|
33
|
|
|
|
|
34
|
|
|
$view = $this->createViewMock($defaultOptions); |
|
35
|
|
|
$optionable = new OptionableView($view, $defaultOptions); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$returned = $optionable->render($this->pagerfanta, $this->routeGenerator); |
|
|
|
|
|
|
38
|
|
|
$this->assertSame($this->rendered, $returned); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testRenderShouldMergeOptions() |
|
42
|
|
|
{ |
|
43
|
|
|
$defaultOptions = array('foo' => 'bar'); |
|
44
|
|
|
$options = array('ups' => 'da'); |
|
45
|
|
|
$expectedOptions = array_merge($defaultOptions, $options); |
|
46
|
|
|
|
|
47
|
|
|
$view = $this->createViewMock($expectedOptions); |
|
48
|
|
|
$optionable = new OptionableView($view, $defaultOptions); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$returned = $optionable->render($this->pagerfanta, $this->routeGenerator, $options); |
|
|
|
|
|
|
51
|
|
|
$this->assertSame($this->rendered, $returned); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function createViewMock($expectedOptions) |
|
55
|
|
|
{ |
|
56
|
|
|
$view = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock(); |
|
57
|
|
|
$view |
|
58
|
|
|
->expects($this->once()) |
|
59
|
|
|
->method('render') |
|
60
|
|
|
->with( |
|
61
|
|
|
$this->equalTo($this->pagerfanta), |
|
62
|
|
|
$this->equalTo($this->routeGenerator), |
|
63
|
|
|
$this->equalTo($expectedOptions) |
|
64
|
|
|
) |
|
65
|
|
|
->will($this->returnValue($this->rendered)); |
|
66
|
|
|
|
|
67
|
|
|
return $view; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
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: