DoctrineDbalSingleTableAdapterTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGetNbResults() 0 4 1
A testGetNbResultsShouldWorkAfterCallingGetSlice() 0 6 1
A doTestGetNbResults() 0 4 1
A testGetNbResultWithNoData() 0 7 1
A testGetSlice() 0 4 1
A testGetSliceShouldWorkAfterCallingGetNbResults() 0 6 1
A doTestGetSlice() 0 12 1
A testItShouldThrowAnInvalidArgumentExceptionIfTheCountFieldDoesNotHaveAlias() 0 4 1
A testItShouldThrowAnInvalidArgumentExceptionIfTheQueryHasJoins() 0 6 1
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Pagerfanta\Adapter\DoctrineDbalSingleTableAdapter;
6
7
class DoctrineDbalSingleTableAdapterTest extends DoctrineDbalTestCase
8
{
9
    /**
10
     * @var DoctrineDbalSingleTableAdapter
11
     */
12
    private $adapter;
13
14
    protected function setUp()
15
    {
16
        parent::setUp();
17
18
        $this->adapter = new DoctrineDbalSingleTableAdapter($this->qb, 'p.id');
19
    }
20
21
    public function testGetNbResults()
22
    {
23
        $this->doTestGetNbResults();
24
    }
25
26
    public function testGetNbResultsShouldWorkAfterCallingGetSlice()
27
    {
28
        $this->adapter->getSlice(1, 10);
29
30
        $this->doTestGetNbResults();
31
    }
32
33
    private function doTestGetNbResults()
34
    {
35
        $this->assertSame(50, $this->adapter->getNbResults());
36
    }
37
38
    public function testGetNbResultWithNoData()
39
    {
40
        $q = clone $this->qb;
41
        $q->delete('posts')->execute();
42
43
        $this->assertSame(0, $this->adapter->getNbResults());
44
    }
45
46
    public function testGetSlice()
47
    {
48
        $this->doTestGetSlice();
49
    }
50
51
    public function testGetSliceShouldWorkAfterCallingGetNbResults()
52
    {
53
        $this->adapter->getNbResults();
54
55
        $this->doTestGetSlice();
56
    }
57
58
    private function doTestGetSlice()
59
    {
60
        $offset = 30;
61
        $length = 10;
62
63
        $q = clone $this->qb;
64
        $q->setFirstResult($offset)->setMaxResults($length);
65
        $expectedResults = $q->execute()->fetchAll();
66
67
        $results = $this->adapter->getSlice($offset, $length);
68
        $this->assertSame($expectedResults, $results);
69
    }
70
71
    /**
72
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
73
     */
74
    public function testItShouldThrowAnInvalidArgumentExceptionIfTheCountFieldDoesNotHaveAlias()
75
    {
76
        new DoctrineDbalSingleTableAdapter($this->qb, 'id');
77
    }
78
79
    /**
80
     * @expectedException \Pagerfanta\Exception\InvalidArgumentException
81
     */
82
    public function testItShouldThrowAnInvalidArgumentExceptionIfTheQueryHasJoins()
83
    {
84
        $this->qb->innerJoin('p', 'comments', 'c', 'c.post_id = p.id');
85
86
        new DoctrineDbalSingleTableAdapter($this->qb, 'p.id');
87
    }
88
}
89