Completed
Push — master ( 74c3c7...591b88 )
by Eric
08:09
created

DataSourceBuilderTest::testParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Grid\Tests\DataSource\Doctrine\ORM;
13
14
use Doctrine\ORM\Query;
15
use Doctrine\ORM\Query\Expr;
16
use Doctrine\ORM\QueryBuilder;
17
use Lug\Component\Grid\DataSource\ArrayDataSource;
18
use Lug\Component\Grid\DataSource\DataSourceBuilderInterface;
19
use Lug\Component\Grid\DataSource\Doctrine\ORM\DataSourceBuilder;
20
use Lug\Component\Grid\DataSource\Doctrine\ORM\ExpressionBuilder;
21
use Lug\Component\Grid\DataSource\PagerfantaDataSource;
22
use Lug\Component\Resource\Repository\Doctrine\ORM\Repository;
23
use Pagerfanta\Adapter\DoctrineORMAdapter;
24
25
/**
26
 * @author GeLo <[email protected]>
27
 */
28
class DataSourceBuilderTest extends \PHPUnit_Framework_TestCase
29
{
30
    /**
31
     * @var DataSourceBuilder
32
     */
33
    private $builder;
34
35
    /**
36
     * @var \PHPUnit_Framework_MockObject_MockObject|Repository
37
     */
38
    private $repository;
39
40
    /**
41
     * @var \PHPUnit_Framework_MockObject_MockObject|QueryBuilder
42
     */
43
    private $queryBuilder;
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function setUp()
49
    {
50
        $this->repository = $this->createRepositoryMock();
51
        $this->queryBuilder = $this->createQueryBuilderMock();
52
53
        $this->repository
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Resource\R...Doctrine\ORM\Repository.

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...
54
            ->expects($this->once())
55
            ->method('createQueryBuilderForCollection')
56
            ->will($this->returnValue($this->queryBuilder));
57
58
        $this->builder = new DataSourceBuilder($this->repository);
59
    }
60
61
    public function testInheritance()
62
    {
63
        $this->assertInstanceOf(DataSourceBuilderInterface::class, $this->builder);
64
    }
65
66 View Code Duplication
    public function testSelect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
69
            ->expects($this->once())
70
            ->method('addSelect')
71
            ->with($this->identicalTo($select = 'alias'));
72
73
        $this->assertSame($this->builder, $this->builder->select($select));
74
    }
75
76
    public function testInnerJoin()
77
    {
78
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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
            ->expects($this->once())
80
            ->method('innerJoin')
81
            ->with(
82
                $this->identicalTo($join = 'property'),
83
                $this->identicalTo($alias = 'alias')
84
            );
85
86
        $this->assertSame($this->builder, $this->builder->innerJoin($join, $alias));
87
    }
88
89
    public function testLeftJoin()
90
    {
91
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
92
            ->expects($this->once())
93
            ->method('leftJoin')
94
            ->with(
95
                $this->identicalTo($join = 'property'),
96
                $this->identicalTo($alias = 'alias')
97
            );
98
99
        $this->assertSame($this->builder, $this->builder->leftJoin($join, $alias));
100
    }
101
102 View Code Duplication
    public function testAndWhere()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
105
            ->expects($this->once())
106
            ->method('andWhere')
107
            ->with($this->identicalTo($where = 'expression'));
108
109
        $this->assertSame($this->builder, $this->builder->andWhere($where));
110
    }
111
112 View Code Duplication
    public function testOrWhere()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
115
            ->expects($this->once())
116
            ->method('orWhere')
117
            ->with($this->identicalTo($where = 'expression'));
118
119
        $this->assertSame($this->builder, $this->builder->orWhere($where));
120
    }
121
122 View Code Duplication
    public function testOrderBy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
125
            ->expects($this->once())
126
            ->method('addOrderBy')
127
            ->with(
128
                $this->identicalTo($sort = 'expression'),
129
                $this->identicalTo('ASC')
130
            );
131
132
        $this->assertSame($this->builder, $this->builder->orderBy($sort));
133
    }
134
135
    public function testOrderByWithOrder()
136
    {
137
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
138
            ->expects($this->once())
139
            ->method('addOrderBy')
140
            ->with(
141
                $this->identicalTo($sort = 'expression'),
142
                $this->identicalTo($order = 'DESC')
143
            );
144
145
        $this->assertSame($this->builder, $this->builder->orderBy($sort, $order));
146
    }
147
148
    public function testParameter()
149
    {
150
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
151
            ->expects($this->once())
152
            ->method('setParameter')
153
            ->with(
154
                $this->identicalTo($parameter = 'parameter'),
155
                $this->identicalTo($value = 'value')
156
            );
157
158
        $this->assertSame($this->builder, $this->builder->setParameter($parameter, $value));
159
    }
160
161
    public function testParameterWithType()
162
    {
163
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
164
            ->expects($this->once())
165
            ->method('setParameter')
166
            ->with(
167
                $this->identicalTo($parameter = 'parameter'),
168
                $this->identicalTo($value = 'value'),
169
                $this->identicalTo($type = 'type')
170
            );
171
172
        $this->assertSame($this->builder, $this->builder->setParameter($parameter, $value, $type));
173
    }
174
175
    public function testPlaceholder()
176
    {
177
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
178
            ->expects($this->once())
179
            ->method('setParameter')
180
            ->with(
181
                $this->matchesRegularExpression('/'.($pattern = 'foo_bar_[a-z0-9]{22}').'/'),
182
                $this->identicalTo($value = 'value')
183
            );
184
185
        $this->assertRegExp('/\:'.$pattern.'/', $this->builder->createPlaceholder('foo.bar', $value));
186
    }
187
188
    public function testPlaceholderUnicity()
189
    {
190
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
191
            ->expects($this->exactly(2))
192
            ->method('setParameter')
193
            ->with(
194
                $this->matchesRegularExpression('/'.($pattern = 'foo_bar_[a-z0-9]{22}').'/'),
195
                $this->identicalTo($value = 'value')
196
            );
197
198
        $this->assertRegExp(
199
            $resultPattern = '/\:'.$pattern.'/',
200
            $placeholder1 = $this->builder->createPlaceholder('foo.bar', $value)
201
        );
202
203
        $this->assertRegExp($resultPattern, $placeholder2 = $this->builder->createPlaceholder('foo.bar', $value));
204
        $this->assertNotSame($placeholder1, $placeholder2);
205
    }
206
207
    public function testProperty()
208
    {
209
        $this->repository
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Resource\R...Doctrine\ORM\Repository.

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...
210
            ->expects($this->once())
211
            ->method('getProperty')
212
            ->with(
213
                $this->identicalTo($field = 'field'),
214
                $this->identicalTo($this->queryBuilder)
215
            )
216
            ->will($this->returnValue($property = 'property'));
217
218
        $this->assertSame($property, $this->builder->getProperty($field));
219
    }
220
221 View Code Duplication
    public function testAliases()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
222
    {
223
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
224
            ->expects($this->once())
225
            ->method('getAllAliases')
226
            ->will($this->returnValue($aliases = ['foo']));
227
228
        $this->assertSame($aliases, $this->builder->getAliases());
229
    }
230
231
    public function testExpressionBuilder()
232
    {
233
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
234
            ->expects($this->once())
235
            ->method('expr')
236
            ->will($this->returnValue($this->createExprMock()));
237
238
        $this->assertInstanceOf(ExpressionBuilder::class, $this->builder->getExpressionBuilder());
239
    }
240
241 View Code Duplication
    public function testCreateDataSource()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
    {
243
        $dataSource = $this->builder->createDataSource();
244
245
        $this->assertInstanceOf(PagerfantaDataSource::class, $dataSource);
246
        $this->assertInstanceOf(DoctrineORMAdapter::class, $dataSource->getAdapter());
0 ignored issues
show
Bug introduced by
The method getAdapter does only exist in Lug\Component\Grid\DataSource\PagerfantaDataSource, but not in Lug\Component\Grid\DataSource\ArrayDataSource.

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...
247
248
        $this->assertSame(10, $dataSource->getMaxPerPage());
0 ignored issues
show
Bug introduced by
The method getMaxPerPage does only exist in Lug\Component\Grid\DataSource\PagerfantaDataSource, but not in Lug\Component\Grid\DataSource\ArrayDataSource.

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...
249
        $this->assertSame(1, $dataSource->getCurrentPage());
0 ignored issues
show
Bug introduced by
The method getCurrentPage does only exist in Lug\Component\Grid\DataSource\PagerfantaDataSource, but not in Lug\Component\Grid\DataSource\ArrayDataSource.

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...
250
    }
251
252
    public function testCreateDataSourceWithAllOption()
253
    {
254
        $this->queryBuilder
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\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...
255
            ->expects($this->once())
256
            ->method('getQuery')
257
            ->will($this->returnValue($query = $this->createQueryMock()));
258
259
        $query
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query.

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...
260
            ->expects($this->once())
261
            ->method('getResult')
262
            ->will($this->returnValue($values = [new \stdClass()]));
263
264
        $dataSource = $this->builder->createDataSource(['all' => true]);
265
266
        $this->assertInstanceOf(ArrayDataSource::class, $dataSource);
267
        $this->assertSame($values, iterator_to_array($dataSource));
268
    }
269
270
    public function testLimit()
271
    {
272
        $this->assertSame($this->builder, $this->builder->setLimit($limit = 20));
273
        $this->assertSame($limit, $this->builder->createDataSource()->getMaxPerPage());
0 ignored issues
show
Bug introduced by
The method getMaxPerPage does only exist in Lug\Component\Grid\DataSource\PagerfantaDataSource, but not in Lug\Component\Grid\DataSource\ArrayDataSource.

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...
274
    }
275
276
    public function testPage()
277
    {
278
        $this->assertSame($this->builder, $this->builder->setPage($page = 1));
279
        $this->assertSame($page, $this->builder->createDataSource()->getCurrentPage());
0 ignored issues
show
Bug introduced by
The method getCurrentPage does only exist in Lug\Component\Grid\DataSource\PagerfantaDataSource, but not in Lug\Component\Grid\DataSource\ArrayDataSource.

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...
280
    }
281
282
    /**
283
     * @return \PHPUnit_Framework_MockObject_MockObject|Repository
284
     */
285
    private function createRepositoryMock()
286
    {
287
        return $this->getMockBuilder(Repository::class)
288
            ->disableOriginalConstructor()
289
            ->getMock();
290
    }
291
292
    /**
293
     * @return \PHPUnit_Framework_MockObject_MockObject|QueryBuilder
294
     */
295
    private function createQueryBuilderMock()
296
    {
297
        return $this->getMockBuilder(QueryBuilder::class)
298
            ->disableOriginalConstructor()
299
            ->disableOriginalClone()
300
            ->getMock();
301
    }
302
303
    /**
304
     * @return \PHPUnit_Framework_MockObject_MockObject|Query
305
     */
306
    private function createQueryMock()
307
    {
308
        return $this->getMock(\stdClass::class, ['getResult']);
309
    }
310
311
    /**
312
     * @return \PHPUnit_Framework_MockObject_MockObject|Expr
313
     */
314
    private function createExprMock()
315
    {
316
        return $this->getMock(Expr::class);
317
    }
318
}
319