Completed
Push — master ( eb83f4...bb238e )
by Maximilian
14s
created

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