PropelAdapterTest::testGetNbResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
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\PropelAdapter;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * PropelAdapterTest
10
 *
11
 * @author William DURAND <[email protected]>
12
 */
13
class PropelAdapterTest extends TestCase
14
{
15
    private $query;
16
    /**
17
     * @var PropelAdapter
18
     */
19
    private $adapter;
20
21
    protected function setUp()
22
    {
23
        if ($this->isPropelNotAvaiable()) {
24
            $this->markTestSkipped('Propel is not available');
25
        }
26
27
        $this->query = $this->createQueryMock();
28
        $this->adapter = new PropelAdapter($this->query);
0 ignored issues
show
Documentation introduced by
$this->query is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<ModelCriteria>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
    }
30
31
    private function isPropelNotAvaiable()
32
    {
33
        return !class_exists('ModelCriteria');
34
    }
35
36
    private function createQueryMock()
37
    {
38
        return $this
39
            ->getMockBuilder('ModelCriteria')
40
            ->disableOriginalConstructor()
41
            ->getMock();
42
    }
43
44
    public function testGetQuery()
45
    {
46
        $this->assertSame($this->query, $this->adapter->getQuery());
47
    }
48
49
    public function testGetNbResults()
50
    {
51
        $this->query
52
            ->expects($this->once())
53
            ->method('limit')
54
            ->with(0);
55
        $this->query
56
            ->expects($this->once())
57
            ->method('offset')
58
            ->with(0);
59
        $this->query
60
            ->expects($this->once())
61
            ->method('count')
62
            ->will($this->returnValue(100));
63
64
        $this->assertSame(100, $this->adapter->getNbResults());
65
    }
66
67
    public function testGetSlice()
68
    {
69
        $offset = 14;
70
        $length = 20;
71
        $slice = new \ArrayObject();
72
73
        $this->query
74
            ->expects($this->once())
75
            ->method('limit')
76
            ->with($length);
77
        $this->query
78
            ->expects($this->once())
79
            ->method('offset')
80
            ->with($offset);
81
        $this->query
82
            ->expects($this->once())
83
            ->method('find')
84
            ->will($this->returnValue($slice));
85
86
        $this->assertSame($slice, $this->adapter->getSlice($offset, $length));
87
    }
88
}
89