Completed
Push — master ( 3af44a...7481f6 )
by
unknown
9s
created

Propel2AdapterTest::createQueryMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Pagerfanta\Adapter\Propel2Adapter;
6
7
/**
8
 * Propel2AdapterTest
9
 *
10
 * @author Claude Khedhiri <[email protected]>
11
 */
12
class Propel2AdapterTest extends \PHPUnit_Framework_TestCase
13
{
14
    private $query;
15
16
    /**
17
     * @var Propel2Adapter
18
     */
19
    private $adapter;
20
21
    protected function setUp()
22
    {
23
        if ($this->isPropel2NotAvaiable()) {
24
            $this->markTestSkipped('Propel 2 is not available');
25
        }
26
27
        $this->query = $this->createQueryMock();
28
        $this->adapter = new Propel2Adapter($this->query);
29
    }
30
31
    private function isPropel2NotAvaiable()
32
    {
33
        return !class_exists('Propel\Runtime\ActiveQuery\ModelCriteria');
34
    }
35
36
    private function createQueryMock()
37
    {
38
        return $this
39
            ->getMockBuilder('Propel\Runtime\ActiveQuery\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('offset')
54
            ->with(0);
55
        $this->query
56
            ->expects($this->once())
57
            ->method('count')
58
            ->will($this->returnValue(100));
59
60
        $this->assertSame(100, $this->adapter->getNbResults());
61
    }
62
63
    public function testGetSlice()
64
    {
65
        $offset = 14;
66
        $length = 20;
67
        $slice = new \ArrayObject();
68
69
        $this->query
70
            ->expects($this->once())
71
            ->method('limit')
72
            ->with($length);
73
        $this->query
74
            ->expects($this->once())
75
            ->method('offset')
76
            ->with($offset);
77
        $this->query
78
            ->expects($this->once())
79
            ->method('find')
80
            ->will($this->returnValue($slice));
81
82
        $this->assertSame($slice, $this->adapter->getSlice($offset, $length));
83
    }
84
}
85