Propel2AdapterTest::testGetSlice()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
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\Propel2Adapter;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * Propel2AdapterTest
10
 *
11
 * @author Claude Khedhiri <[email protected]>
12
 */
13
class Propel2AdapterTest extends TestCase
14
{
15
    private $query;
16
17
    /**
18
     * @var Propel2Adapter
19
     */
20
    private $adapter;
21
22
    protected function setUp()
23
    {
24
        if ($this->isPropel2NotAvaiable()) {
25
            $this->markTestSkipped('Propel 2 is not available');
26
        }
27
28
        $this->query = $this->createQueryMock();
29
        $this->adapter = new Propel2Adapter($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<Propel\Runtime\ActiveQuery\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...
30
    }
31
32
    private function isPropel2NotAvaiable()
33
    {
34
        return !class_exists('Propel\Runtime\ActiveQuery\ModelCriteria');
35
    }
36
37
    private function createQueryMock()
38
    {
39
        return $this
40
            ->getMockBuilder('Propel\Runtime\ActiveQuery\ModelCriteria')
41
            ->disableOriginalConstructor()
42
            ->getMock();
43
    }
44
45
    public function testGetQuery()
46
    {
47
        $this->assertSame($this->query, $this->adapter->getQuery());
48
    }
49
50
    public function testGetNbResults()
51
    {
52
        $this->query
53
            ->expects($this->once())
54
            ->method('offset')
55
            ->with(0);
56
        $this->query
57
            ->expects($this->once())
58
            ->method('count')
59
            ->will($this->returnValue(100));
60
61
        $this->assertSame(100, $this->adapter->getNbResults());
62
    }
63
64
    public function testGetSlice()
65
    {
66
        $offset = 14;
67
        $length = 20;
68
        $slice = new \ArrayObject();
69
70
        $this->query
71
            ->expects($this->once())
72
            ->method('limit')
73
            ->with($length);
74
        $this->query
75
            ->expects($this->once())
76
            ->method('offset')
77
            ->with($offset);
78
        $this->query
79
            ->expects($this->once())
80
            ->method('find')
81
            ->will($this->returnValue($slice));
82
83
        $this->assertSame($slice, $this->adapter->getSlice($offset, $length));
84
    }
85
}
86