Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

unit/AdminList/Helper/DoctrineDBALAdapterTest.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\AdminList;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Doctrine\DBAL\Statement;
7
use Kunstmaan\AdminListBundle\Helper\DoctrineDBALAdapter;
8
use LogicException;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Class AdminListTest
13
 */
14
class DoctrineDBALAdapterTest extends TestCase
15
{
16
    /**
17
     * @var DoctrineDBALAdapter
18
     */
19
    private $adapter;
20
21
    /**
22
     * @var QueryBuilder
23
     */
24
    private $qb;
25
26
    public function setUp()
27
    {
28
        $statement = $this->createMock(Statement::class);
29
        $statement->expects($this->any())->method('fetchAll')->willReturn([1, 2, 3]);
30
        $statement->expects($this->any())->method('fetchColumn')->willReturn([1, 2, 3]);
31
        $qb = $this->createMock(QueryBuilder::class);
32
        $qb->expects($this->any())->method('setMaxResults')->willReturn($qb);
33
        $qb->expects($this->any())->method('setFirstResult')->willReturn($qb);
34
        $qb->expects($this->any())->method('select')->willReturn($qb);
35
        $qb->expects($this->any())->method('orderBy')->willReturn($qb);
36
        $qb->expects($this->any())->method('execute')->willReturn($statement);
37
        $this->qb = $qb;
0 ignored issues
show
Documentation Bug introduced by
It seems like $qb of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\DBAL\Query\QueryBuilder> of property $qb.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
    }
39
40
    public function testGetQueryBuilder()
41
    {
42
        $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT);
0 ignored issues
show
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield');
44
        $this->assertInstanceOf(QueryBuilder::class, $this->adapter->getQueryBuilder());
45
    }
46
47
    public function testConstructorThrowsException()
48
    {
49
        $this->expectException(LogicException::class);
50
        $this->adapter = new DoctrineDBALAdapter($this->qb, 'somefield');
51
    }
52
53
    /**
54
     * @throws \ReflectionException
55
     */
56
    public function testConstructorThrowsAnotherException()
57
    {
58
        $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::DELETE);
0 ignored issues
show
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        $this->expectException(LogicException::class);
61
62
        $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield');
63
    }
64
65 View Code Duplication
    public function testGetSlice()
66
    {
67
        $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT);
0 ignored issues
show
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
        $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield');
69
        $result = $this->adapter->getSlice(0, 3);
70
        $this->assertCount(3, $result);
71
    }
72
73 View Code Duplication
    public function testNbResults()
74
    {
75
        $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT);
0 ignored issues
show
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
        $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield');
77
        $result = $this->adapter->getNbResults();
78
        $this->assertCount(3, $result);
79
    }
80
}
81