Completed
Push — master ( 7af6a5...884bd7 )
by
unknown
21:15
created

tests/Unit/Datagrid/ProxyQueryTest.php (5 issues)

Labels
Severity

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\Query\Builder\QueryBuilder;
17
use PHPUnit\Framework\TestCase;
18
use Sonata\DoctrinePHPCRAdminBundle\Datagrid\ProxyQuery;
19
20
class ProxyQueryTest extends TestCase
21
{
22
    /**
23
     * @var QueryBuilder|\PHPUnit_Framework_MockObject_MockObject
24
     */
25
    private $qb;
26
27
    /**
28
     * @var ProxyQuery
29
     */
30
    private $pq;
31
32
    public function setUp(): void
33
    {
34
        $this->qb = $this->getMockBuilder('Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder')
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
        $this->query = $this->getMockBuilder('Doctrine\ODM\PHPCR\Query\Query')
38
            ->disableOriginalConstructor()
39
            ->getMock();
40
41
        $this->pq = new ProxyQuery($this->qb, 'a');
42
    }
43
44
    public function testConstructor(): void
45
    {
46
        $this->assertInstanceOf('Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder', $this->pq->getQueryBuilder());
47
    }
48
49
    public function testSetSortBy(): void
50
    {
51
        $this->pq->setSortBy([], ['fieldName' => 'field']);
52
        $this->assertEquals('field', $this->pq->getSortBy());
53
    }
54
55
    public function testSetSortOrder(): void
56
    {
57
        $this->pq->setSortOrder('ASC');
58
        $this->assertEquals('ASC', $this->pq->getSortOrder());
59
    }
60
61
    public function testSetSortOrderInvalid(): void
62
    {
63
        $this->expectException(\InvalidArgumentException::class);
64
65
        $this->pq->setSortOrder('SOME_ORDER');
66
        $this->assertEquals('SOME_ORDER', $this->pq->getSortOrder());
67
    }
68
69
    public function testSetFirstResult(): void
70
    {
71
        $this->qb->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
            ->method('setFirstResult')
73
            ->with($this->equalTo(19));
74
75
        $this->pq->setFirstResult(19);
76
    }
77
78
    public function testGetFirstResult(): void
79
    {
80
        $this->qb->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
81
            ->method('getFirstResult');
82
83
        $this->pq->getFirstResult();
84
    }
85
86
    public function testSetMaxResults(): void
87
    {
88
        $this->qb->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
89
            ->method('setMaxResults')
90
            ->with($this->equalTo(29));
91
92
        $this->pq->setMaxResults(29);
93
    }
94
95
    public function testGetMaxResults(): void
96
    {
97
        $this->qb->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
98
            ->method('getMaxResults');
99
100
        $this->pq->getMaxResults();
101
    }
102
103
    public function testExecute(): void
104
    {
105
        $this->qb->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
106
            ->method('getQuery')
107
            ->will($this->returnValue($this->query));
108
        $this->query->expects($this->once())
109
            ->method('execute')
110
            ->will($this->returnValue('test'));
111
112
        $res = $this->pq->execute();
113
        $this->assertEquals('test', $res);
114
    }
115
116
    public function testGetAndSetDocumentManager(): void
117
    {
118
        $dm = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')
119
            ->disableOriginalConstructor()
120
            ->getMock();
121
        $this->pq->setDocumentManager($dm);
122
        $this->assertEquals($dm, $this->pq->getDocumentManager());
123
    }
124
}
125