1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\View; |
4
|
|
|
|
5
|
|
|
use Pagerfanta\Pagerfanta; |
6
|
|
|
use Pagerfanta\View\ViewInterface; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
abstract class ViewTestCase extends TestCase |
10
|
|
|
{ |
11
|
|
|
private $adapter; |
12
|
|
|
/** |
13
|
|
|
* @var Pagerfanta |
14
|
|
|
*/ |
15
|
|
|
private $pagerfanta; |
16
|
|
|
/** |
17
|
|
|
* @var ViewInterface |
18
|
|
|
*/ |
19
|
|
|
private $view; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->adapter = $this->createAdapterMock(); |
24
|
|
|
$this->pagerfanta = new Pagerfanta($this->adapter); |
|
|
|
|
25
|
|
|
$this->view = $this->createView(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
private function createAdapterMock() |
29
|
|
|
{ |
30
|
|
|
return $this->getMockBuilder('Pagerfanta\Adapter\AdapterInterface')->getMock(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return ViewInterface |
35
|
|
|
*/ |
36
|
|
|
abstract protected function createView(); |
37
|
|
|
|
38
|
|
|
protected function setNbPages($nbPages) |
39
|
|
|
{ |
40
|
|
|
$nbResults = $this->calculateNbResults($nbPages); |
41
|
|
|
|
42
|
|
|
$this->adapter |
43
|
|
|
->expects($this->any()) |
44
|
|
|
->method('getNbResults') |
45
|
|
|
->will($this->returnValue($nbResults)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function calculateNbResults($nbPages) |
49
|
|
|
{ |
50
|
|
|
return $nbPages * $this->pagerfanta->getMaxPerPage(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function setCurrentPage($currentPage) |
54
|
|
|
{ |
55
|
|
|
$this->pagerfanta->setCurrentPage($currentPage); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function renderView($options) |
59
|
|
|
{ |
60
|
|
|
$routeGenerator = $this->createRouteGenerator(); |
61
|
|
|
|
62
|
|
|
return $this->view->render($this->pagerfanta, $routeGenerator, $options); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function createRouteGenerator() |
66
|
|
|
{ |
67
|
|
|
return function ($page) { return '|'.$page.'|'; }; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function assertRenderedView($expected, $result) |
71
|
|
|
{ |
72
|
|
|
$this->assertSame($this->filterExpectedView($expected), $result); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function filterExpectedView($expected) |
76
|
|
|
{ |
77
|
|
|
return $expected; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function removeWhitespacesBetweenTags($string) |
81
|
|
|
{ |
82
|
|
|
return preg_replace('/>\s+</', '><', $string); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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: