testGetNbResultShouldReturnTheGetNbResultsCallbackReturnValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Pagerfanta\Adapter\CallbackAdapter;
6
use PHPUnit\Framework\TestCase;
7
8
class CallbackAdapterTest extends TestCase
9
{
10
    /**
11
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
12
     * @dataProvider notCallbackProvider
13
     */
14
    public function testConstructorShouldThrowAnInvalidArgumentExceptionIfTheGetNbResultsCallbackIsNotACallback($value)
15
    {
16
        new CallbackAdapter($value, function () {});
17
    }
18
19
    /**
20
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
21
     * @dataProvider notCallbackProvider
22
     */
23
    public function testConstructorShouldThrowAnInvalidArgumentExceptionIfTheGetSliceCallbackIsNotACallback($value)
24
    {
25
        new CallbackAdapter(function () {}, $value);
26
    }
27
28
    public function notCallbackProvider()
29
    {
30
        return array(
31
            array('foo'),
32
            array(1),
33
        );
34
    }
35
36
    public function testGetNbResultShouldReturnTheGetNbResultsCallbackReturnValue()
37
    {
38
        $getNbResultsCallback = function () {
39
            return 42;
40
        };
41
        $adapter = new CallbackAdapter($getNbResultsCallback, function () {});
42
43
        $this->assertEquals(42, $adapter->getNbResults());
44
    }
45
46
    public function testGetSliceShouldReturnTheGetSliceCallbackReturnValue()
47
    {
48
        $results = new \ArrayObject();
49
        $getSliceCallback = function () use ($results) {
50
            return $results;
51
        };
52
53
        $adapter = new CallbackAdapter(function () {}, $getSliceCallback);
54
55
        $this->assertSame($results, $adapter->getSlice(1, 1));
56
    }
57
58
    public function testGetSliceShouldPassTheOffsetAndLengthToTheGetSliceCallback()
59
    {
60
        $testCase = $this;
61
        $getSliceCallback = function ($offset, $length) use ($testCase) {
62
            $testCase->assertSame(10, $offset);
63
            $testCase->assertSame(18, $length);
64
        };
65
66
        $adapter = new CallbackAdapter(function () {}, $getSliceCallback);
67
        $adapter->getSlice(10, 18);
68
    }
69
}
70