MandangoAdapterTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 0
loc 86
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 2
A isMandangoNotAvailable() 0 4 1
A createQueryMock() 0 7 1
A testGetQuery() 0 4 1
A testGetNbResults() 0 10 1
A testGetResults() 0 12 1
A prepareQueryLimit() 0 8 1
A prepareQuerySkip() 0 8 1
A prepareQueryAll() 0 7 1
1
<?php
2
3
namespace Pagerfanta\Tests\Adapter;
4
5
use Pagerfanta\Adapter\MandangoAdapter;
6
use PHPUnit\Framework\TestCase;
7
8
class MandangoAdapterTest extends TestCase
9
{
10
    private $query;
11
    /**
12
     * @var MandangoAdapter
13
     */
14
    private $adapter;
15
16
    protected function setUp()
17
    {
18
        if ($this->isMandangoNotAvailable()) {
19
            $this->markTestSkipped('Mandango is not available');
20
        }
21
22
        $this->query = $this->createQueryMock();
23
        $this->adapter = new MandangoAdapter($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<Mandango\Query>.

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...
24
    }
25
26
    private function isMandangoNotAvailable()
27
    {
28
        return !class_exists('Mandango\Query');
29
    }
30
31
    private function createQueryMock()
32
    {
33
        return $this
34
            ->getMockBuilder('Mandango\Query')
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
    }
38
39
    public function testGetQuery()
40
    {
41
        $this->assertSame($this->query, $this->adapter->getQuery());
42
    }
43
44
    public function testGetNbResults()
45
    {
46
        $this->query
47
            ->expects($this->once())
48
            ->method('count')
49
            ->will($this->returnValue(100))
50
        ;
51
52
        $this->assertSame(100, $this->adapter->getNbResults());
53
    }
54
55
    public function testGetResults()
56
    {
57
        $offset = 14;
58
        $length = 30;
59
        $slice = new \ArrayObject();
60
61
        $this->prepareQuerySkip($offset);
62
        $this->prepareQueryLimit($length);
63
        $this->prepareQueryAll($slice);
64
65
        $this->assertSame($slice, $this->adapter->getSlice($offset, $length));
66
    }
67
68
    private function prepareQueryLimit($limit)
69
    {
70
        $this->query
71
            ->expects($this->once())
72
            ->method('limit')
73
            ->with($limit)
74
            ->will($this->returnValue($this->query));
75
    }
76
77
    private function prepareQuerySkip($skip)
78
    {
79
        $this->query
80
            ->expects($this->once())
81
            ->method('skip')
82
            ->with($skip)
83
            ->will($this->returnValue($this->query));
84
    }
85
86
    private function prepareQueryAll($all)
87
    {
88
        $this->query
89
            ->expects($this->once())
90
            ->method('all')
91
            ->will($this->returnValue($all));
92
    }
93
}
94