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

ExpressionBuilderTest::testNotIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 9
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\Expr;
15
use Lug\Component\Grid\DataSource\Doctrine\ORM\ExpressionBuilder;
16
use Lug\Component\Grid\DataSource\ExpressionBuilderInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class ExpressionBuilderTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var ExpressionBuilder
25
     */
26
    private $builder;
27
28
    /**
29
     * @var \PHPUnit_Framework_MockObject_MockObject|Expr
30
     */
31
    private $expr;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function setUp()
37
    {
38
        $this->expr = $this->createExprMock();
39
        $this->builder = new ExpressionBuilder($this->expr);
40
    }
41
42
    public function testInheritance()
43
    {
44
        $this->assertInstanceOf(ExpressionBuilderInterface::class, $this->builder);
45
    }
46
47
    public function testAndX()
48
    {
49
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
50
            ->expects($this->once())
51
            ->method('andX')
52
            ->with(
53
                $this->identicalTo($expression1 = 'expression1'),
54
                $this->identicalTo($expression2 = 'expression2')
55
            )
56
            ->will($this->returnValue($expression = 'expression'));
57
58
        $this->assertSame($expression, $this->builder->andX([$expression1, $expression2]));
59
    }
60
61
    public function testOrX()
62
    {
63
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
64
            ->expects($this->once())
65
            ->method('orX')
66
            ->with(
67
                $this->identicalTo($expression1 = 'expression1'),
68
                $this->identicalTo($expression2 = 'expression2')
69
            )
70
            ->will($this->returnValue($expression = 'expression'));
71
72
        $this->assertSame($expression, $this->builder->orX([$expression1, $expression2]));
73
    }
74
75
    public function testAsc()
76
    {
77
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
78
            ->expects($this->once())
79
            ->method('asc')
80
            ->with($this->identicalTo($x = 'property'))
81
            ->will($this->returnValue($expression = 'expression'));
82
83
        $this->assertSame($expression, $this->builder->asc($x));
84
    }
85
86
    public function testDesc()
87
    {
88
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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
            ->expects($this->once())
90
            ->method('desc')
91
            ->with($this->identicalTo($x = 'property'))
92
            ->will($this->returnValue($expression = 'expression'));
93
94
        $this->assertSame($expression, $this->builder->desc($x));
95
    }
96
97
    public function testEq()
98
    {
99
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
100
            ->expects($this->once())
101
            ->method('eq')
102
            ->with(
103
                $this->identicalTo($x = 'property'),
104
                $this->identicalTo($y = 'placeholder')
105
            )
106
            ->will($this->returnValue($expression = 'expression'));
107
108
        $this->assertSame($expression, $this->builder->eq($x, $y));
109
    }
110
111
    public function testNeq()
112
    {
113
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
114
            ->expects($this->once())
115
            ->method('neq')
116
            ->with(
117
                $this->identicalTo($x = 'property'),
118
                $this->identicalTo($y = 'placeholder')
119
            )
120
            ->will($this->returnValue($expression = 'expression'));
121
122
        $this->assertSame($expression, $this->builder->neq($x, $y));
123
    }
124
125
    public function testLt()
126
    {
127
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
128
            ->expects($this->once())
129
            ->method('lt')
130
            ->with(
131
                $this->identicalTo($x = 'property'),
132
                $this->identicalTo($y = 'placeholder')
133
            )
134
            ->will($this->returnValue($expression = 'expression'));
135
136
        $this->assertSame($expression, $this->builder->lt($x, $y));
137
    }
138
139
    public function testLte()
140
    {
141
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
142
            ->expects($this->once())
143
            ->method('lte')
144
            ->with(
145
                $this->identicalTo($x = 'property'),
146
                $this->identicalTo($y = 'placeholder')
147
            )
148
            ->will($this->returnValue($expression = 'expression'));
149
150
        $this->assertSame($expression, $this->builder->lte($x, $y));
151
    }
152
153
    public function testGt()
154
    {
155
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
156
            ->expects($this->once())
157
            ->method('gt')
158
            ->with(
159
                $this->identicalTo($x = 'property'),
160
                $this->identicalTo($y = 'placeholder')
161
            )
162
            ->will($this->returnValue($expression = 'expression'));
163
164
        $this->assertSame($expression, $this->builder->gt($x, $y));
165
    }
166
167
    public function testGte()
168
    {
169
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
170
            ->expects($this->once())
171
            ->method('gte')
172
            ->with(
173
                $this->identicalTo($x = 'property'),
174
                $this->identicalTo($y = 'placeholder')
175
            )
176
            ->will($this->returnValue($expression = 'expression'));
177
178
        $this->assertSame($expression, $this->builder->gte($x, $y));
179
    }
180
181 View Code Duplication
    public function testExists()
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...
182
    {
183
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
184
            ->expects($this->once())
185
            ->method('exists')
186
            ->with($this->identicalTo($x = 'property'))
187
            ->will($this->returnValue($expression = 'expression'));
188
189
        $this->assertSame($expression, $this->builder->exists($x));
190
    }
191
192
    public function testIn()
193
    {
194
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
195
            ->expects($this->once())
196
            ->method('in')
197
            ->with(
198
                $this->identicalTo($x = 'property'),
199
                $this->identicalTo($y = 'placeholder')
200
            )
201
            ->will($this->returnValue($expression = 'expression'));
202
203
        $this->assertSame($expression, $this->builder->in($x, $y));
204
    }
205
206
    public function testNotIn()
207
    {
208
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
209
            ->expects($this->once())
210
            ->method('notIn')
211
            ->with(
212
                $this->identicalTo($x = 'property'),
213
                $this->identicalTo($y = 'placeholder')
214
            )
215
            ->will($this->returnValue($expression = 'expression'));
216
217
        $this->assertSame($expression, $this->builder->notIn($x, $y));
218
    }
219
220 View Code Duplication
    public function testIsNull()
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...
221
    {
222
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
223
            ->expects($this->once())
224
            ->method('isNull')
225
            ->with($this->identicalTo($x = 'property'))
226
            ->will($this->returnValue($expression = 'expression'));
227
228
        $this->assertSame($expression, $this->builder->isNull($x));
229
    }
230
231 View Code Duplication
    public function testIsNotNull()
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...
232
    {
233
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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('isNotNull')
236
            ->with($this->identicalTo($x = 'property'))
237
            ->will($this->returnValue($expression = 'expression'));
238
239
        $this->assertSame($expression, $this->builder->isNotNull($x));
240
    }
241
242
    public function testLike()
243
    {
244
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
245
            ->expects($this->once())
246
            ->method('like')
247
            ->with(
248
                $this->identicalTo($x = 'property'),
249
                $this->identicalTo($y = 'placeholder')
250
            )
251
            ->will($this->returnValue($expression = 'expression'));
252
253
        $this->assertSame($expression, $this->builder->like($x, $y));
254
    }
255
256
    public function testNotLike()
257
    {
258
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
259
            ->expects($this->once())
260
            ->method('notLike')
261
            ->with(
262
                $this->identicalTo($x = 'property'),
263
                $this->identicalTo($y = 'placeholder')
264
            )
265
            ->will($this->returnValue($expression = 'expression'));
266
267
        $this->assertSame($expression, $this->builder->notLike($x, $y));
268
    }
269
270
    public function testBetween()
271
    {
272
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
273
            ->expects($this->once())
274
            ->method('between')
275
            ->with(
276
                $this->identicalTo($value = 'property'),
277
                $this->identicalTo($x = 'placeholder1'),
278
                $this->identicalTo($y = 'placeholder2')
279
            )
280
            ->will($this->returnValue($expression = 'expression'));
281
282
        $this->assertSame($expression, $this->builder->between($value, $x, $y));
283
    }
284
285
    public function testNotBetween()
286
    {
287
        $this->expr
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\Query\Expr.

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...
288
            ->expects($this->once())
289
            ->method('between')
290
            ->with(
291
                $this->identicalTo($value = 'property'),
292
                $this->identicalTo($x = 'placeholder1'),
293
                $this->identicalTo($y = 'placeholder2')
294
            )
295
            ->will($this->returnValue($betweenExpression = 'between_expression'));
296
297
        $this->expr
298
            ->expects($this->once())
299
            ->method('not')
300
            ->with($this->identicalTo($betweenExpression))
301
            ->will($this->returnValue($expression = 'expression'));
302
303
        $this->assertSame($expression, $this->builder->notBetween($value, $x, $y));
304
    }
305
306
    /**
307
     * @return \PHPUnit_Framework_MockObject_MockObject|Expr
308
     */
309
    private function createExprMock()
310
    {
311
        return $this->getMock(Expr::class);
312
    }
313
}
314