Completed
Push — 5.6 ( 889235...c60ee9 )
by Jeroen
27s queued 12s
created

testNbResultsWithZeroResults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\AdminList\Helper;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Doctrine\DBAL\Statement;
7
use Kunstmaan\AdminListBundle\Helper\DoctrineDBALAdapter;
8
use PHPUnit\Framework\TestCase;
9
10
class DoctrineDBALAdapterTest extends TestCase
11
{
12
    /**
13
     * @expectedException \LogicException
14
     * @expectedExceptionMessage The $countField must contain a table alias in the string.
15
     */
16
    public function testConstructorWithIncorrectCountField()
17
    {
18
        $qb = $this->createMock(QueryBuilder::class);
19
        new DoctrineDBALAdapter($qb, 'somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
20
    }
21
22
    public function testGetQueryBuilder()
23
    {
24
        $qb = $this->createMock(QueryBuilder::class);
25
        $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT);
26
        $adapter = new DoctrineDBALAdapter($qb, 'table.somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
27
28
        $this->assertInstanceOf(QueryBuilder::class, $adapter->getQueryBuilder());
29
    }
30
31
    /**
32
     * @expectedException \LogicException
33
     * @expectedExceptionMessage Only SELECT queries can be paginated.
34
     */
35
    public function testConstructorThrowsAnotherException()
36
    {
37
        $qb = $this->createMock(QueryBuilder::class);
38
        $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::DELETE);
39
40
        new DoctrineDBALAdapter($qb, 'table.somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
41
    }
42
43
    public function testGetSlice()
44
    {
45
        $length = 3;
46
47
        $statement = $this->createMock(Statement::class);
48
        $statement->expects($this->once())->method('fetchAll')->willReturn([1, 2, 3]);
49
        $qb = $this->createMock(QueryBuilder::class);
50
        $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT);
51
        $qb->expects($this->once())->method('setFirstResult')->willReturn($qb);
52
        $qb->expects($this->once())->method('setMaxResults')->with($length)->willReturn($qb);
53
        $qb->expects($this->once())->method('execute')->willReturn($statement);
54
55
        $adapter = new DoctrineDBALAdapter($qb, 'table.somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
56
        $result = $adapter->getSlice(0, $length);
57
        $this->assertCount($length, $result);
58
    }
59
60
    public function testNbResults()
61
    {
62
        $statement = $this->createMock(Statement::class);
63
        $statement->expects($this->once())->method('fetchColumn')->with(0)->willReturn([1, 2, 3]);
64
        $qb = $this->createMock(QueryBuilder::class);
65
        $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT);
66
        $qb->expects($this->once())->method('select')->willReturn($qb);
67
        $qb->expects($this->once())->method('orderBy')->willReturn($qb);
68
        $qb->expects($this->once())->method('setMaxResults')->with(1)->willReturn($qb);
69
        $qb->expects($this->once())->method('execute')->willReturn($statement);
70
71
        $adapter = new DoctrineDBALAdapter($qb, 'table.somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
72
        $result = $adapter->getNbResults();
73
        $this->assertCount(3, $result);
0 ignored issues
show
Documentation introduced by
$result is of type integer, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
74
    }
75
76
    public function testNbResultsWithZeroResults()
77
    {
78
        $statement = $this->createMock(Statement::class);
79
        $statement->expects($this->once())->method('fetchColumn')->with(0)->willReturn(null);
80
        $qb = $this->createMock(QueryBuilder::class);
81
        $qb->expects($this->once())->method('getType')->willReturn(QueryBuilder::SELECT);
82
        $qb->expects($this->once())->method('select')->willReturn($qb);
83
        $qb->expects($this->once())->method('orderBy')->willReturn($qb);
84
        $qb->expects($this->once())->method('setMaxResults')->with(1)->willReturn($qb);
85
        $qb->expects($this->once())->method('execute')->willReturn($statement);
86
87
        $adapter = new DoctrineDBALAdapter($qb, 'table.somefield');
0 ignored issues
show
Documentation introduced by
$qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Query\QueryBuilder>.

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...
88
        $result = $adapter->getNbResults();
89
        $this->assertSame(0, $result);
90
    }
91
}
92