Completed
Push — master ( 6b2632...1706e7 )
by
unknown
07:57 queued 10s
created

tests/Unit/Datagrid/ProxyQueryTest.php (2 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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Datagrid;
15
16
use Doctrine\ODM\PHPCR\DocumentManager;
17
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
18
use Doctrine\ODM\PHPCR\Query\Query;
19
use PHPUnit\Framework\TestCase;
20
use Sonata\DoctrinePHPCRAdminBundle\Datagrid\ProxyQuery;
21
22
class ProxyQueryTest extends TestCase
23
{
24
    /**
25
     * @var QueryBuilder|\PHPUnit_Framework_MockObject_MockObject
26
     */
27
    private $qb;
28
29
    /**
30
     * @var ProxyQuery
31
     */
32
    private $pq;
33
34
    public function setUp(): void
35
    {
36
        $this->qb = $this->createMock(QueryBuilder::class);
37
        $this->query = $this->createMock(Query::class);
38
39
        $this->pq = new ProxyQuery($this->qb, 'a');
0 ignored issues
show
$this->qb is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\PHPC...y\Builder\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...
40
    }
41
42
    public function testConstructor(): void
43
    {
44
        $this->assertInstanceOf(QueryBuilder::class, $this->pq->getQueryBuilder());
45
    }
46
47
    public function testSetSortBy(): void
48
    {
49
        $this->pq->setSortBy([], ['fieldName' => 'field']);
50
        $this->assertSame('field', $this->pq->getSortBy());
51
    }
52
53
    public function testSetSortOrder(): void
54
    {
55
        $this->pq->setSortOrder('ASC');
56
        $this->assertSame('ASC', $this->pq->getSortOrder());
57
    }
58
59
    public function testSetSortOrderInvalid(): void
60
    {
61
        $this->expectException(\InvalidArgumentException::class);
62
63
        $this->pq->setSortOrder('SOME_ORDER');
64
        $this->assertSame('SOME_ORDER', $this->pq->getSortOrder());
65
    }
66
67
    public function testSetFirstResult(): void
68
    {
69
        $this->qb->expects($this->once())
70
            ->method('setFirstResult')
71
            ->with($this->equalTo(19));
72
73
        $this->pq->setFirstResult(19);
74
    }
75
76
    public function testGetFirstResult(): void
77
    {
78
        $this->qb->expects($this->once())
79
            ->method('getFirstResult');
80
81
        $this->pq->getFirstResult();
82
    }
83
84
    public function testSetMaxResults(): void
85
    {
86
        $this->qb->expects($this->once())
87
            ->method('setMaxResults')
88
            ->with($this->equalTo(29));
89
90
        $this->pq->setMaxResults(29);
91
    }
92
93
    public function testGetMaxResults(): void
94
    {
95
        $this->qb->expects($this->once())
96
            ->method('getMaxResults');
97
98
        $this->pq->getMaxResults();
99
    }
100
101
    public function testExecute(): void
102
    {
103
        $this->qb->expects($this->once())
104
            ->method('getQuery')
105
            ->willReturn($this->query);
106
        $this->query->expects($this->once())
107
            ->method('execute')
108
            ->willReturn('test');
109
110
        $res = $this->pq->execute();
111
        $this->assertSame('test', $res);
112
    }
113
114
    public function testGetAndSetDocumentManager(): void
115
    {
116
        $dm = $this->createMock(DocumentManager::class);
117
        $this->pq->setDocumentManager($dm);
0 ignored issues
show
$dm is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\PHPCR\DocumentManager>.

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...
118
        $this->assertSame($dm, $this->pq->getDocumentManager());
119
    }
120
}
121