1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagerfanta\Tests\Adapter; |
4
|
|
|
|
5
|
|
|
use Pagerfanta\Adapter\ArrayAdapter; |
6
|
|
|
use Pagerfanta\Adapter\CallbackAdapter; |
7
|
|
|
use Pagerfanta\Adapter\ConcatenationAdapter; |
8
|
|
|
use Pagerfanta\Adapter\FixedAdapter; |
9
|
|
|
use Pagerfanta\Adapter\NullAdapter; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class ConcatenationAdapterTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testConstructor() |
15
|
|
|
{ |
16
|
|
|
new ConcatenationAdapter(array( |
17
|
|
|
new ArrayAdapter(array()), |
18
|
|
|
new NullAdapter(), |
19
|
|
|
new FixedAdapter(0, array()) |
20
|
|
|
)); |
21
|
|
|
|
22
|
|
|
$this->expectException( |
23
|
|
|
'\Pagerfanta\Exception\InvalidArgumentException' |
24
|
|
|
); |
25
|
|
|
new ConcatenationAdapter(array( |
|
|
|
|
26
|
|
|
new ArrayAdapter(array()), |
27
|
|
|
'foo' |
28
|
|
|
)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetNbResults() |
32
|
|
|
{ |
33
|
|
|
$adapter = new ConcatenationAdapter(array( |
34
|
|
|
new ArrayAdapter(array('foo', 'bar', 'baz')) |
35
|
|
|
)); |
36
|
|
|
$this->assertEquals(3, $adapter->getNbResults()); |
37
|
|
|
|
38
|
|
|
$adapter = new ConcatenationAdapter(array( |
39
|
|
|
new ArrayAdapter(array_fill(0, 4, 'foo')), |
40
|
|
|
new ArrayAdapter(array_fill(0, 6, 'bar')), |
41
|
|
|
new ArrayAdapter(array('baq')) |
42
|
|
|
)); |
43
|
|
|
$this->assertEquals(11, $adapter->getNbResults()); |
44
|
|
|
|
45
|
|
|
$adapter = new ConcatenationAdapter(array()); |
46
|
|
|
$this->assertEquals(0, $adapter->getNbResults()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetResults() |
50
|
|
|
{ |
51
|
|
|
$adapter = new ConcatenationAdapter(array( |
52
|
|
|
new ArrayAdapter(array(1, 2, 3, 4, 5, 6)), |
53
|
|
|
new ArrayAdapter(array(7, 8, 9, 10, 11, 12, 13, 14)), |
54
|
|
|
new ArrayAdapter(array(15, 16, 17)) |
55
|
|
|
)); |
56
|
|
|
$this->assertEquals(array(8, 9, 10), $adapter->getSlice(7, 3)); |
57
|
|
|
$this->assertEquals(array(5, 6, 7, 8), $adapter->getSlice(4, 4)); |
58
|
|
|
$this->assertEquals(array(6, 7, 8, 9, 10, 11, 12, 13, 14, 15), $adapter->getSlice(5, 10)); |
59
|
|
|
$this->assertEquals(array(16, 17), $adapter->getSlice(15, 5)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testWithTraversableAdapter() |
63
|
|
|
{ |
64
|
|
|
$adapter = new ConcatenationAdapter(array( |
65
|
|
|
new CallbackAdapter( |
66
|
|
|
function () { |
67
|
|
|
return 5; |
68
|
|
|
}, |
69
|
|
|
function ($offset, $length) { |
70
|
|
|
return new \ArrayIterator(array_slice(array(1, 2, 3, 4, 5), $offset, $length)); |
71
|
|
|
} |
72
|
|
|
), |
73
|
|
|
new CallbackAdapter( |
74
|
|
|
function () { |
75
|
|
|
return 3; |
76
|
|
|
}, |
77
|
|
|
function ($offset, $length) { |
78
|
|
|
return new \ArrayIterator(array_slice(array(6, 7, 8), $offset, $length)); |
79
|
|
|
} |
80
|
|
|
) |
81
|
|
|
)); |
82
|
|
|
$this->assertEquals(array(2, 3), $adapter->getSlice(1, 2)); |
83
|
|
|
$this->assertEquals(array(4, 5, 6), $adapter->getSlice(3, 3)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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: