Passed
Pull Request — master (#8013)
by Roman
09:42 queued 49s
created

testSetParametersWithInvalidSignature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Criteria;
9
use Doctrine\ORM\Cache;
10
use Doctrine\ORM\Query;
11
use Doctrine\ORM\Query\Parameter;
12
use Doctrine\ORM\Query\ParameterTypeInferer;
13
use Doctrine\ORM\QueryBuilder;
14
use Doctrine\Tests\Mocks\EntityManagerMock;
15
use Doctrine\Tests\Models\Cache\State;
16
use Doctrine\Tests\Models\CMS\CmsArticle;
17
use Doctrine\Tests\Models\CMS\CmsGroup;
18
use Doctrine\Tests\Models\CMS\CmsUser;
19
use Doctrine\Tests\OrmTestCase;
20
use InvalidArgumentException;
21
use function array_filter;
22
use function get_class;
23
24
/**
25
 * Test case for the QueryBuilder class used to build DQL query string in a
26
 * object oriented way.
27
 */
28
class QueryBuilderTest extends OrmTestCase
29
{
30
    /** @var EntityManagerMock */
31
    private $em;
32
33
    protected function setUp() : void
34
    {
35
        $this->em = $this->getTestEntityManager();
36
    }
37
38
    protected function assertValidQueryBuilder(QueryBuilder $qb, $expectedDql)
39
    {
40
        $dql = $qb->getDQL();
41
        $q   = $qb->getQuery();
0 ignored issues
show
Unused Code introduced by
The assignment to $q is dead and can be removed.
Loading history...
42
43
        self::assertEquals($expectedDql, $dql);
44
    }
45
46
    public function testSelectSetsType() : void
47
    {
48
        $qb = $this->em->createQueryBuilder()
49
            ->delete(CmsUser::class, 'u')
50
            ->select('u.id', 'u.username');
51
52
        self::assertEquals($qb->getType(), QueryBuilder::SELECT);
53
    }
54
55
    public function testEmptySelectSetsType() : void
56
    {
57
        $qb = $this->em->createQueryBuilder()
58
            ->delete(CmsUser::class, 'u')
59
            ->select();
60
61
        self::assertEquals($qb->getType(), QueryBuilder::SELECT);
62
    }
63
64
    public function testDeleteSetsType() : void
65
    {
66
        $qb = $this->em->createQueryBuilder()
67
            ->from(CmsUser::class, 'u')
68
            ->delete();
69
70
        self::assertEquals($qb->getType(), QueryBuilder::DELETE);
71
    }
72
73
    public function testUpdateSetsType() : void
74
    {
75
        $qb = $this->em->createQueryBuilder()
76
            ->from(CmsUser::class, 'u')
77
            ->update();
78
79
        self::assertEquals($qb->getType(), QueryBuilder::UPDATE);
80
    }
81
82
    public function testSimpleSelect() : void
83
    {
84
        $qb = $this->em->createQueryBuilder()
85
            ->from(CmsUser::class, 'u')
86
            ->select('u.id', 'u.username');
87
88
        self::assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
        self::/** @scrutinizer ignore-call */ 
89
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
Loading history...
89
    }
90
91
    public function testSimpleDelete() : void
92
    {
93
        $qb = $this->em->createQueryBuilder()
94
            ->delete(CmsUser::class, 'u');
95
96
        self::assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        self::/** @scrutinizer ignore-call */ 
97
              assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u');
Loading history...
97
    }
98
99
    public function testSimpleSelectWithFromIndexBy() : void
100
    {
101
        $qb = $this->em->createQueryBuilder()
102
            ->from(CmsUser::class, 'u', 'u.id')
103
            ->select('u.id', 'u.username');
104
105
        self::assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        self::/** @scrutinizer ignore-call */ 
106
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
Loading history...
106
    }
107
108
    public function testSimpleSelectWithIndexBy() : void
109
    {
110
        $qb = $this->em->createQueryBuilder()
111
            ->from(CmsUser::class, 'u')
112
            ->indexBy('u', 'u.id')
113
            ->select('u.id', 'u.username');
114
115
        self::assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
        self::/** @scrutinizer ignore-call */ 
116
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
Loading history...
116
    }
117
118
    public function testSimpleUpdate() : void
119
    {
120
        $qb = $this->em->createQueryBuilder()
121
            ->update(CmsUser::class, 'u')
122
            ->set('u.username', ':username');
123
124
        self::assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        self::/** @scrutinizer ignore-call */ 
125
              assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username');
Loading history...
125
    }
126
127
    public function testInnerJoin() : void
128
    {
129
        $qb = $this->em->createQueryBuilder()
130
            ->select('u', 'a')
131
            ->from(CmsUser::class, 'u')
132
            ->innerJoin('u.articles', 'a');
133
134
        self::assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
        self::/** @scrutinizer ignore-call */ 
135
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a');
Loading history...
135
    }
136
137
    public function testComplexInnerJoin() : void
138
    {
139
        $qb = $this->em->createQueryBuilder()
140
            ->select('u', 'a')
141
            ->from(CmsUser::class, 'u')
142
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id');
143
144
        self::assertValidQueryBuilder(
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
        self::/** @scrutinizer ignore-call */ 
145
              assertValidQueryBuilder(
Loading history...
145
            $qb,
146
            'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id'
147
        );
148
    }
149
150
    public function testComplexInnerJoinWithIndexBy() : void
151
    {
152
        $qb = $this->em->createQueryBuilder()
153
            ->select('u', 'a')
154
            ->from(CmsUser::class, 'u')
155
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id', 'a.name');
156
157
        self::assertValidQueryBuilder(
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

157
        self::/** @scrutinizer ignore-call */ 
158
              assertValidQueryBuilder(
Loading history...
158
            $qb,
159
            'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a INDEX BY a.name ON u.id = a.author_id'
160
        );
161
    }
162
163
    public function testLeftJoin() : void
164
    {
165
        $qb = $this->em->createQueryBuilder()
166
            ->select('u', 'a')
167
            ->from(CmsUser::class, 'u')
168
            ->leftJoin('u.articles', 'a');
169
170
        self::assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
        self::/** @scrutinizer ignore-call */ 
171
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a');
Loading history...
171
    }
172
173
    public function testLeftJoinWithIndexBy() : void
174
    {
175
        $qb = $this->em->createQueryBuilder()
176
            ->select('u', 'a')
177
            ->from(CmsUser::class, 'u')
178
            ->leftJoin('u.articles', 'a', null, null, 'a.name');
179
180
        self::assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.name');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
        self::/** @scrutinizer ignore-call */ 
181
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.name');
Loading history...
181
    }
182
183
    public function testMultipleFrom() : void
184
    {
185
        $qb = $this->em->createQueryBuilder()
186
            ->select('u', 'g')
187
            ->from(CmsUser::class, 'u')
188
            ->from(CmsGroup::class, 'g');
189
190
        self::assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

190
        self::/** @scrutinizer ignore-call */ 
191
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g');
Loading history...
191
    }
192
193
    public function testMultipleFromWithIndexBy() : void
194
    {
195
        $qb = $this->em->createQueryBuilder()
196
            ->select('u', 'g')
197
            ->from(CmsUser::class, 'u')
198
            ->from(CmsGroup::class, 'g')
199
            ->indexBy('g', 'g.id');
200
201
        self::assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g INDEX BY g.id');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

201
        self::/** @scrutinizer ignore-call */ 
202
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g INDEX BY g.id');
Loading history...
202
    }
203
204
    public function testMultipleFromWithJoin() : void
205
    {
206
        $qb = $this->em->createQueryBuilder()
207
            ->select('u', 'g')
208
            ->from(CmsUser::class, 'u')
209
            ->from(CmsGroup::class, 'g')
210
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id');
211
212
        self::assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id, Doctrine\Tests\Models\CMS\CmsGroup g');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

212
        self::/** @scrutinizer ignore-call */ 
213
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id, Doctrine\Tests\Models\CMS\CmsGroup g');
Loading history...
213
    }
214
215
    public function testMultipleFromWithMultipleJoin() : void
216
    {
217
        $qb = $this->em->createQueryBuilder()
218
            ->select('u', 'g')
219
            ->from(CmsUser::class, 'u')
220
            ->from(CmsArticle::class, 'a')
221
            ->innerJoin('u.groups', 'g')
222
            ->leftJoin('u.address', 'ad')
223
            ->innerJoin('a.comments', 'c');
224
225
        self::assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g LEFT JOIN u.address ad, Doctrine\Tests\Models\CMS\CmsArticle a INNER JOIN a.comments c');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

225
        self::/** @scrutinizer ignore-call */ 
226
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g LEFT JOIN u.address ad, Doctrine\Tests\Models\CMS\CmsArticle a INNER JOIN a.comments c');
Loading history...
226
    }
227
228
    public function testWhere() : void
229
    {
230
        $qb = $this->em->createQueryBuilder()
231
            ->select('u')
232
            ->from(CmsUser::class, 'u')
233
            ->where('u.id = :uid');
234
235
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

235
        self::/** @scrutinizer ignore-call */ 
236
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid');
Loading history...
236
    }
237
238
    public function testComplexAndWhere() : void
239
    {
240
        $qb = $this->em->createQueryBuilder()
241
            ->select('u')
242
            ->from(CmsUser::class, 'u')
243
            ->where('u.id = :uid OR u.id = :uid2 OR u.id = :uid3')
244
            ->andWhere('u.name = :name');
245
246
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid OR u.id = :uid2 OR u.id = :uid3) AND u.name = :name');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

246
        self::/** @scrutinizer ignore-call */ 
247
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid OR u.id = :uid2 OR u.id = :uid3) AND u.name = :name');
Loading history...
247
    }
248
249
    public function testAndWhere() : void
250
    {
251
        $qb = $this->em->createQueryBuilder()
252
            ->select('u')
253
            ->from(CmsUser::class, 'u')
254
            ->where('u.id = :uid')
255
            ->andWhere('u.id = :uid2');
256
257
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

257
        self::/** @scrutinizer ignore-call */ 
258
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
258
    }
259
260
    public function testOrWhere() : void
261
    {
262
        $qb = $this->em->createQueryBuilder()
263
            ->select('u')
264
            ->from(CmsUser::class, 'u')
265
            ->where('u.id = :uid')
266
            ->orWhere('u.id = :uid2');
267
268
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

268
        self::/** @scrutinizer ignore-call */ 
269
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
Loading history...
269
    }
270
271
    public function testComplexAndWhereOrWhereNesting() : void
272
    {
273
        $qb = $this->em->createQueryBuilder();
274
        $qb->select('u')
275
           ->from(CmsUser::class, 'u')
276
           ->where('u.id = :uid')
277
           ->orWhere('u.id = :uid2')
278
           ->andWhere('u.id = :uid3')
279
           ->orWhere('u.name = :name1', 'u.name = :name2')
280
           ->andWhere('u.name <> :noname');
281
282
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (((u.id = :uid OR u.id = :uid2) AND u.id = :uid3) OR u.name = :name1 OR u.name = :name2) AND u.name <> :noname');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

282
        self::/** @scrutinizer ignore-call */ 
283
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (((u.id = :uid OR u.id = :uid2) AND u.id = :uid3) OR u.name = :name1 OR u.name = :name2) AND u.name <> :noname');
Loading history...
283
    }
284
285
    public function testAndWhereIn() : void
286
    {
287
        $qb = $this->em->createQueryBuilder();
288
        $qb->select('u')
289
           ->from(CmsUser::class, 'u')
290
           ->where('u.id = :uid')
291
           ->andWhere($qb->expr()->in('u.id', [1, 2, 3]));
292
293
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id IN(1, 2, 3)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

293
        self::/** @scrutinizer ignore-call */ 
294
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id IN(1, 2, 3)');
Loading history...
294
    }
295
296
    public function testOrWhereIn() : void
297
    {
298
        $qb = $this->em->createQueryBuilder();
299
        $qb->select('u')
300
           ->from(CmsUser::class, 'u')
301
           ->where('u.id = :uid')
302
           ->orWhere($qb->expr()->in('u.id', [1, 2, 3]));
303
304
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id IN(1, 2, 3)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

304
        self::/** @scrutinizer ignore-call */ 
305
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id IN(1, 2, 3)');
Loading history...
305
    }
306
307
    public function testAndWhereNotIn() : void
308
    {
309
        $qb = $this->em->createQueryBuilder();
310
        $qb->select('u')
311
           ->from(CmsUser::class, 'u')
312
           ->where('u.id = :uid')
313
           ->andWhere($qb->expr()->notIn('u.id', [1, 2, 3]));
314
315
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id NOT IN(1, 2, 3)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

315
        self::/** @scrutinizer ignore-call */ 
316
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id NOT IN(1, 2, 3)');
Loading history...
316
    }
317
318
    public function testOrWhereNotIn() : void
319
    {
320
        $qb = $this->em->createQueryBuilder();
321
        $qb->select('u')
322
           ->from(CmsUser::class, 'u')
323
           ->where('u.id = :uid')
324
           ->orWhere($qb->expr()->notIn('u.id', [1, 2, 3]));
325
326
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id NOT IN(1, 2, 3)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

326
        self::/** @scrutinizer ignore-call */ 
327
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id NOT IN(1, 2, 3)');
Loading history...
327
    }
328
329
    public function testGroupBy() : void
330
    {
331
        $qb = $this->em->createQueryBuilder()
332
            ->select('u')
333
            ->from(CmsUser::class, 'u')
334
            ->groupBy('u.id')
335
            ->addGroupBy('u.username');
336
337
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id, u.username');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

337
        self::/** @scrutinizer ignore-call */ 
338
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id, u.username');
Loading history...
338
    }
339
340
    public function testHaving() : void
341
    {
342
        $qb = $this->em->createQueryBuilder()
343
            ->select('u')
344
            ->from(CmsUser::class, 'u')
345
            ->groupBy('u.id')
346
            ->having('COUNT(u.id) > 1');
347
348
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

348
        self::/** @scrutinizer ignore-call */ 
349
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1');
Loading history...
349
    }
350
351
    public function testAndHaving() : void
352
    {
353
        $qb = $this->em->createQueryBuilder()
354
            ->select('u')
355
            ->from(CmsUser::class, 'u')
356
            ->groupBy('u.id')
357
            ->having('COUNT(u.id) > 1')
358
            ->andHaving('COUNT(u.id) < 1');
359
360
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1 AND COUNT(u.id) < 1');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

360
        self::/** @scrutinizer ignore-call */ 
361
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1 AND COUNT(u.id) < 1');
Loading history...
361
    }
362
363
    public function testOrHaving() : void
364
    {
365
        $qb = $this->em->createQueryBuilder()
366
            ->select('u')
367
            ->from(CmsUser::class, 'u')
368
            ->groupBy('u.id')
369
            ->having('COUNT(u.id) > 1')
370
            ->andHaving('COUNT(u.id) < 1')
371
            ->orHaving('COUNT(u.id) > 1');
372
373
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING (COUNT(u.id) > 1 AND COUNT(u.id) < 1) OR COUNT(u.id) > 1');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

373
        self::/** @scrutinizer ignore-call */ 
374
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING (COUNT(u.id) > 1 AND COUNT(u.id) < 1) OR COUNT(u.id) > 1');
Loading history...
374
    }
375
376
    public function testOrderBy() : void
377
    {
378
        $qb = $this->em->createQueryBuilder()
379
            ->select('u')
380
            ->from(CmsUser::class, 'u')
381
            ->orderBy('u.username', 'ASC');
382
383
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

383
        self::/** @scrutinizer ignore-call */ 
384
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
Loading history...
384
    }
385
386
    public function testOrderByWithExpression() : void
387
    {
388
        $qb = $this->em->createQueryBuilder();
389
        $qb->select('u')
390
            ->from(CmsUser::class, 'u')
391
            ->orderBy($qb->expr()->asc('u.username'));
392
393
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

393
        self::/** @scrutinizer ignore-call */ 
394
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
Loading history...
394
    }
395
396
    public function testAddOrderBy() : void
397
    {
398
        $qb = $this->em->createQueryBuilder()
399
            ->select('u')
400
            ->from(CmsUser::class, 'u')
401
            ->orderBy('u.username', 'ASC')
402
            ->addOrderBy('u.username', 'DESC');
403
404
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

404
        self::/** @scrutinizer ignore-call */ 
405
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
Loading history...
405
    }
406
407
    public function testAddOrderByWithExpression() : void
408
    {
409
        $qb = $this->em->createQueryBuilder();
410
        $qb->select('u')
411
            ->from(CmsUser::class, 'u')
412
            ->orderBy('u.username', 'ASC')
413
            ->addOrderBy($qb->expr()->desc('u.username'));
414
415
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

415
        self::/** @scrutinizer ignore-call */ 
416
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
Loading history...
416
    }
417
418
    public function testAddCriteriaWhere() : void
419
    {
420
        $qb = $this->em->createQueryBuilder();
421
        $qb->select('u')
422
            ->from(CmsUser::class, 'u');
423
424
        $criteria = new Criteria();
425
        $criteria->where($criteria->expr()->eq('field', 'value'));
426
427
        $qb->addCriteria($criteria);
428
429
        self::assertEquals('u.field = :field', (string) $qb->getDQLPart('where'));
430
        self::assertNotNull($qb->getParameter('field'));
431
    }
432
433
    public function testAddMultipleSameCriteriaWhere() : void
434
    {
435
        $qb = $this->em->createQueryBuilder();
436
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
437
438
        $criteria = new Criteria();
439
        $criteria->where($criteria->expr()->andX(
440
            $criteria->expr()->eq('field', 'value1'),
441
            $criteria->expr()->eq('field', 'value2')
442
        ));
443
444
        $qb->addCriteria($criteria);
445
446
        self::assertEquals('alias1.field = :field AND alias1.field = :field_1', (string) $qb->getDQLPart('where'));
447
        self::assertNotNull($qb->getParameter('field'));
448
        self::assertNotNull($qb->getParameter('field_1'));
449
    }
450
451
    /**
452
     * @group DDC-2844
453
     */
454
    public function testAddCriteriaWhereWithMultipleParametersWithSameField() : void
455
    {
456
        $qb = $this->em->createQueryBuilder();
457
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
458
459
        $criteria = new Criteria();
460
        $criteria->where($criteria->expr()->eq('field', 'value1'));
461
        $criteria->andWhere($criteria->expr()->gt('field', 'value2'));
462
463
        $qb->addCriteria($criteria);
464
465
        self::assertEquals('alias1.field = :field AND alias1.field > :field_1', (string) $qb->getDQLPart('where'));
466
        self::assertSame('value1', $qb->getParameter('field')->getValue());
467
        self::assertSame('value2', $qb->getParameter('field_1')->getValue());
468
    }
469
470
    /**
471
     * @group DDC-2844
472
     */
473
    public function testAddCriteriaWhereWithMultipleParametersWithDifferentFields() : void
474
    {
475
        $qb = $this->em->createQueryBuilder();
476
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
477
478
        $criteria = new Criteria();
479
        $criteria->where($criteria->expr()->eq('field1', 'value1'));
480
        $criteria->andWhere($criteria->expr()->gt('field2', 'value2'));
481
482
        $qb->addCriteria($criteria);
483
484
        self::assertEquals('alias1.field1 = :field1 AND alias1.field2 > :field2', (string) $qb->getDQLPart('where'));
485
        self::assertSame('value1', $qb->getParameter('field1')->getValue());
486
        self::assertSame('value2', $qb->getParameter('field2')->getValue());
487
    }
488
489
    /**
490
     * @group DDC-2844
491
     */
492
    public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndDifferentProperties() : void
493
    {
494
        $qb = $this->em->createQueryBuilder();
495
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
496
497
        $criteria = new Criteria();
498
        $criteria->where($criteria->expr()->eq('field1', 'value1'));
499
        $criteria->andWhere($criteria->expr()->gt('field2', 'value2'));
500
501
        $qb->addCriteria($criteria);
502
503
        self::assertEquals('alias1.field1 = :field1 AND alias1.field2 > :field2', (string) $qb->getDQLPart('where'));
504
        self::assertSame('value1', $qb->getParameter('field1')->getValue());
505
        self::assertSame('value2', $qb->getParameter('field2')->getValue());
506
    }
507
508
    /**
509
     * @group DDC-2844
510
     */
511
    public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndSameProperty() : void
512
    {
513
        $qb = $this->em->createQueryBuilder();
514
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
515
516
        $criteria = new Criteria();
517
        $criteria->where($criteria->expr()->eq('field1', 'value1'));
518
        $criteria->andWhere($criteria->expr()->gt('field1', 'value2'));
519
520
        $qb->addCriteria($criteria);
521
522
        self::assertEquals('alias1.field1 = :field1 AND alias1.field1 > :field1_1', (string) $qb->getDQLPart('where'));
523
        self::assertSame('value1', $qb->getParameter('field1')->getValue());
524
        self::assertSame('value2', $qb->getParameter('field1_1')->getValue());
525
    }
526
527
    public function testAddCriteriaOrder() : void
528
    {
529
        $qb = $this->em->createQueryBuilder();
530
        $qb->select('u')
531
            ->from(CmsUser::class, 'u');
532
533
        $criteria = new Criteria();
534
        $criteria->orderBy(['field' => Criteria::DESC]);
535
536
        $qb->addCriteria($criteria);
537
538
        self::assertCount(1, $orderBy = $qb->getDQLPart('orderBy'));
539
        self::assertEquals('u.field DESC', (string) $orderBy[0]);
540
    }
541
542
    /**
543
     * @group DDC-3108
544
     */
545
    public function testAddCriteriaOrderOnJoinAlias() : void
546
    {
547
        $qb = $this->em->createQueryBuilder();
548
        $qb->select('u')
549
            ->from(CmsUser::class, 'u')
550
            ->join('u.article', 'a');
551
552
        $criteria = new Criteria();
553
        $criteria->orderBy(['a.field' => Criteria::DESC]);
554
555
        $qb->addCriteria($criteria);
556
557
        self::assertCount(1, $orderBy = $qb->getDQLPart('orderBy'));
558
        self::assertEquals('a.field DESC', (string) $orderBy[0]);
559
    }
560
561
    public function testAddCriteriaLimit() : void
562
    {
563
        $qb = $this->em->createQueryBuilder();
564
        $qb->select('u')
565
            ->from(CmsUser::class, 'u');
566
567
        $criteria = new Criteria();
568
        $criteria->setFirstResult(2);
569
        $criteria->setMaxResults(10);
570
571
        $qb->addCriteria($criteria);
572
573
        self::assertEquals(2, $qb->getFirstResult());
574
        self::assertEquals(10, $qb->getMaxResults());
575
    }
576
577
    public function testAddCriteriaUndefinedLimit() : void
578
    {
579
        $qb = $this->em->createQueryBuilder();
580
        $qb->select('u')
581
            ->from(CmsUser::class, 'u')
582
            ->setFirstResult(2)
583
            ->setMaxResults(10);
584
585
        $criteria = new Criteria();
586
587
        $qb->addCriteria($criteria);
588
589
        self::assertEquals(2, $qb->getFirstResult());
590
        self::assertEquals(10, $qb->getMaxResults());
591
    }
592
593
    public function testGetQuery() : void
594
    {
595
        $qb = $this->em->createQueryBuilder()
596
            ->select('u')
597
            ->from(CmsUser::class, 'u');
598
        $q  = $qb->getQuery();
599
600
        self::assertEquals(Query::class, get_class($q));
601
    }
602
603
    public function testSetParameter() : void
604
    {
605
        $qb = $this->em->createQueryBuilder()
606
            ->select('u')
607
            ->from(CmsUser::class, 'u')
608
            ->where('u.id = :id')
609
            ->setParameter('id', 1);
610
611
        $parameter = new Parameter('id', 1, ParameterTypeInferer::inferType(1));
612
        $inferred  = $qb->getParameter('id');
613
614
        self::assertSame($parameter->getValue(), $inferred->getValue());
615
        self::assertSame($parameter->getType(), $inferred->getType());
616
        self::assertFalse($inferred->typeWasSpecified());
617
    }
618
619
    public function testSetParameters() : void
620
    {
621
        $qb = $this->em->createQueryBuilder();
622
        $qb->select('u')
623
           ->from(CmsUser::class, 'u')
624
           ->where($qb->expr()->orX('u.username = :username', 'u.username = :username2'));
625
626
        $parameters = new ArrayCollection();
627
        $parameters->add(new Parameter('username', 'jwage'));
628
        $parameters->add(new Parameter('username2', 'jonwage'));
629
630
        $qb->setParameters($parameters);
631
632
        self::assertEquals($parameters, $qb->getQuery()->getParameters());
633
    }
634
635
    public function testGetParameters() : void
636
    {
637
        $qb = $this->em->createQueryBuilder();
638
        $qb->select('u')
639
           ->from(CmsUser::class, 'u')
640
           ->where('u.id = :id');
641
642
        $parameters = new ArrayCollection();
643
        $parameters->add(new Parameter('id', 1));
644
645
        $qb->setParameters($parameters);
646
647
        self::assertEquals($parameters, $qb->getParameters());
648
    }
649
650
    public function testGetParameter() : void
651
    {
652
        $qb = $this->em->createQueryBuilder()
653
            ->select('u')
654
            ->from(CmsUser::class, 'u')
655
            ->where('u.id = :id');
656
657
        $parameters = new ArrayCollection();
658
        $parameters->add(new Parameter('id', 1));
659
660
        $qb->setParameters($parameters);
661
662
        self::assertEquals($parameters->first(), $qb->getParameter('id'));
663
    }
664
665
    public function testSetParametersWithInvalidSignature() : void
666
    {
667
        $qb = $this->em->createQueryBuilder()
668
            ->select('u')
669
            ->from(CmsUser::class, 'u')
670
            ->where('u.id = :id');
671
672
        $parameters = new ArrayCollection(['key' => 'value']);
673
674
        $qb->setParameters($parameters);
675
676
        $this->expectException(Query\QueryException::class);
677
        $this->expectExceptionMessage('Set parameter must be instance of \Doctrine\ORM\Query\Parameter');
678
679
        $qb->getQuery()->getSQL();
680
    }
681
682
    public function testMultipleWhere() : void
683
    {
684
        $qb = $this->em->createQueryBuilder()
685
            ->select('u')
686
            ->from(CmsUser::class, 'u')
687
            ->where('u.id = :uid', 'u.id = :uid2');
688
689
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

689
        self::/** @scrutinizer ignore-call */ 
690
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
690
    }
691
692
    public function testMultipleAndWhere() : void
693
    {
694
        $qb = $this->em->createQueryBuilder()
695
            ->select('u')
696
            ->from(CmsUser::class, 'u')
697
            ->andWhere('u.id = :uid', 'u.id = :uid2');
698
699
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

699
        self::/** @scrutinizer ignore-call */ 
700
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
700
    }
701
702
    public function testMultipleOrWhere() : void
703
    {
704
        $qb = $this->em->createQueryBuilder();
705
        $qb->select('u')
706
           ->from(CmsUser::class, 'u')
707
           ->orWhere('u.id = :uid', $qb->expr()->eq('u.id', ':uid2'));
708
709
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

709
        self::/** @scrutinizer ignore-call */ 
710
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
Loading history...
710
    }
711
712
    public function testComplexWhere() : void
713
    {
714
        $qb     = $this->em->createQueryBuilder();
715
        $orExpr = $qb->expr()->orX();
716
        $orExpr->add($qb->expr()->eq('u.id', ':uid3'));
717
        $orExpr->add($qb->expr()->in('u.id', [1]));
718
719
        $qb->select('u')
720
           ->from(CmsUser::class, 'u')
721
           ->where($orExpr);
722
723
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR u.id IN(1)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

723
        self::/** @scrutinizer ignore-call */ 
724
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR u.id IN(1)');
Loading history...
724
    }
725
726
    public function testWhereInWithStringLiterals() : void
727
    {
728
        $qb = $this->em->createQueryBuilder();
729
        $qb->select('u')
730
           ->from(CmsUser::class, 'u')
731
           ->where($qb->expr()->in('u.name', ['one', 'two', 'three']));
732
733
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

733
        self::/** @scrutinizer ignore-call */ 
734
              assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
Loading history...
734
735
        $qb->where($qb->expr()->in('u.name', ["O'Reilly", "O'Neil", 'Smith']));
736
737
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')");
738
    }
739
740
    public function testWhereInWithObjectLiterals() : void
741
    {
742
        $qb   = $this->em->createQueryBuilder();
743
        $expr = $this->em->getExpressionBuilder();
744
        $qb->select('u')
745
           ->from(CmsUser::class, 'u')
746
           ->where($expr->in('u.name', [$expr->literal('one'), $expr->literal('two'), $expr->literal('three')]));
747
748
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

748
        self::/** @scrutinizer ignore-call */ 
749
              assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
Loading history...
749
750
        $qb->where($expr->in('u.name', [$expr->literal("O'Reilly"), $expr->literal("O'Neil"), $expr->literal('Smith')]));
751
752
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')");
753
    }
754
755
    public function testNegation() : void
756
    {
757
        $expr   = $this->em->getExpressionBuilder();
758
        $orExpr = $expr->orX();
759
        $orExpr->add($expr->eq('u.id', ':uid3'));
760
        $orExpr->add($expr->not($expr->in('u.id', [1])));
761
762
        $qb = $this->em->createQueryBuilder();
763
        $qb->select('u')
764
           ->from(CmsUser::class, 'u')
765
           ->where($orExpr);
766
767
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR NOT(u.id IN(1))');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

767
        self::/** @scrutinizer ignore-call */ 
768
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR NOT(u.id IN(1))');
Loading history...
768
    }
769
770
    public function testSomeAllAny() : void
771
    {
772
        $qb   = $this->em->createQueryBuilder();
773
        $expr = $this->em->getExpressionBuilder();
774
775
        $qb->select('u')
776
           ->from(CmsUser::class, 'u')
777
           ->where($expr->gt('u.id', $expr->all('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a')));
778
779
        self::assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL(select a.id from Doctrine\Tests\Models\CMS\CmsArticle a)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

779
        self::/** @scrutinizer ignore-call */ 
780
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL(select a.id from Doctrine\Tests\Models\CMS\CmsArticle a)');
Loading history...
780
    }
781
782
    public function testMultipleIsolatedQueryConstruction() : void
783
    {
784
        $qb   = $this->em->createQueryBuilder();
785
        $expr = $this->em->getExpressionBuilder();
786
787
        $qb->select('u')->from(CmsUser::class, 'u');
788
        $qb->where($expr->eq('u.name', ':name'));
789
        $qb->setParameter('name', 'romanb');
790
791
        $q1 = $qb->getQuery();
792
793
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name', $q1->getDQL());
794
        self::assertCount(1, $q1->getParameters());
795
796
        // add another condition and construct a second query
797
        $qb->andWhere($expr->eq('u.id', ':id'));
798
        $qb->setParameter('id', 42);
799
800
        $q2 = $qb->getQuery();
801
802
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name AND u.id = :id', $q2->getDQL());
803
        self::assertNotSame($q1, $q2); // two different, independent queries
804
        self::assertCount(2, $q2->getParameters());
805
        self::assertCount(1, $q1->getParameters()); // $q1 unaffected
806
    }
807
808
    public function testGetEntityManager() : void
809
    {
810
        $qb = $this->em->createQueryBuilder();
811
        self::assertEquals($this->em->getWrappedEntityManager(), $qb->getEntityManager());
812
    }
813
814
    public function testInitialStateIsClean() : void
815
    {
816
        $qb = $this->em->createQueryBuilder();
817
        self::assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
818
    }
819
820
    public function testAlteringQueryChangesStateToDirty() : void
821
    {
822
        $qb = $this->em->createQueryBuilder()
823
            ->select('u')
824
            ->from(CmsUser::class, 'u');
825
826
        self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
827
    }
828
829
    public function testSelectWithFuncExpression() : void
830
    {
831
        $qb   = $this->em->createQueryBuilder();
832
        $expr = $qb->expr();
833
        $qb->select($expr->count('e.id'));
834
835
        self::assertValidQueryBuilder($qb, 'SELECT COUNT(e.id)');
0 ignored issues
show
Bug Best Practice introduced by
The method Doctrine\Tests\ORM\Query...sertValidQueryBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

835
        self::/** @scrutinizer ignore-call */ 
836
              assertValidQueryBuilder($qb, 'SELECT COUNT(e.id)');
Loading history...
836
    }
837
838
    public function testResetDQLPart() : void
839
    {
840
        $qb = $this->em->createQueryBuilder()
841
            ->select('u')
842
            ->from(CmsUser::class, 'u')
843
            ->where('u.username = ?1')->orderBy('u.username');
844
845
        self::assertEquals('u.username = ?1', (string) $qb->getDQLPart('where'));
846
        self::assertCount(1, $qb->getDQLPart('orderBy'));
847
848
        $qb->resetDQLPart('where')->resetDQLPart('orderBy');
849
850
        self::assertNull($qb->getDQLPart('where'));
851
        self::assertCount(0, $qb->getDQLPart('orderBy'));
852
    }
853
854
    public function testResetDQLParts() : void
855
    {
856
        $qb = $this->em->createQueryBuilder()
857
            ->select('u')
858
            ->from(CmsUser::class, 'u')
859
            ->where('u.username = ?1')->orderBy('u.username');
860
861
        $qb->resetDQLParts(['where', 'orderBy']);
862
863
        self::assertCount(1, $qb->getDQLPart('select'));
864
        self::assertNull($qb->getDQLPart('where'));
865
        self::assertCount(0, $qb->getDQLPart('orderBy'));
866
    }
867
868
    public function testResetAllDQLParts() : void
869
    {
870
        $qb = $this->em->createQueryBuilder()
871
            ->select('u')
872
            ->from(CmsUser::class, 'u')
873
            ->where('u.username = ?1')->orderBy('u.username');
874
875
        $qb->resetDQLParts();
876
877
        self::assertCount(0, $qb->getDQLPart('select'));
878
        self::assertNull($qb->getDQLPart('where'));
879
        self::assertCount(0, $qb->getDQLPart('orderBy'));
880
    }
881
882
    /**
883
     * @group DDC-867
884
     */
885
    public function testDeepClone() : void
886
    {
887
        $qb = $this->em->createQueryBuilder()
888
            ->select('u')
889
            ->from(CmsUser::class, 'u')
890
            ->andWhere('u.username = ?1')
891
            ->andWhere('u.status = ?2');
892
893
        $expr = $qb->getDQLPart('where');
894
        self::assertEquals(2, $expr->count(), 'Modifying the second query should affect the first one.');
895
896
        $qb2 = clone $qb;
897
        $qb2->andWhere('u.name = ?3');
898
899
        self::assertEquals(2, $expr->count(), 'Modifying the second query should affect the first one.');
900
    }
901
902
    /**
903
     * @group DDC-3108
904
     */
905
    public function testAddCriteriaWhereWithJoinAlias() : void
906
    {
907
        $qb = $this->em->createQueryBuilder();
908
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
909
        $qb->join('alias1.articles', 'alias2');
910
911
        $criteria = new Criteria();
912
        $criteria->where($criteria->expr()->eq('field', 'value1'));
913
        $criteria->andWhere($criteria->expr()->gt('alias2.field', 'value2'));
914
915
        $qb->addCriteria($criteria);
916
917
        self::assertEquals('alias1.field = :field AND alias2.field > :alias2_field', (string) $qb->getDQLPart('where'));
918
        self::assertSame('value1', $qb->getParameter('field')->getValue());
919
        self::assertSame('value2', $qb->getParameter('alias2_field')->getValue());
920
    }
921
922
    /**
923
     * @group DDC-3108
924
     */
925
    public function testAddCriteriaWhereWithDefaultAndJoinAlias() : void
926
    {
927
        $qb = $this->em->createQueryBuilder();
928
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
929
        $qb->join('alias1.articles', 'alias2');
930
931
        $criteria = new Criteria();
932
        $criteria->where($criteria->expr()->eq('alias1.field', 'value1'));
933
        $criteria->andWhere($criteria->expr()->gt('alias2.field', 'value2'));
934
935
        $qb->addCriteria($criteria);
936
937
        self::assertEquals('alias1.field = :alias1_field AND alias2.field > :alias2_field', (string) $qb->getDQLPart('where'));
938
        self::assertSame('value1', $qb->getParameter('alias1_field')->getValue());
939
        self::assertSame('value2', $qb->getParameter('alias2_field')->getValue());
940
    }
941
942
    /**
943
     * @group DDC-3108
944
     */
945
    public function testAddCriteriaWhereOnJoinAliasWithDuplicateFields() : void
946
    {
947
        $qb = $this->em->createQueryBuilder();
948
        $qb->select('alias1')->from(CmsUser::class, 'alias1');
949
        $qb->join('alias1.articles', 'alias2');
950
951
        $criteria = new Criteria();
952
        $criteria->where($criteria->expr()->eq('alias1.field', 'value1'));
953
        $criteria->andWhere($criteria->expr()->gt('alias2.field', 'value2'));
954
        $criteria->andWhere($criteria->expr()->lt('alias2.field', 'value3'));
955
956
        $qb->addCriteria($criteria);
957
958
        self::assertEquals('(alias1.field = :alias1_field AND alias2.field > :alias2_field) AND alias2.field < :alias2_field_2', (string) $qb->getDQLPart('where'));
959
        self::assertSame('value1', $qb->getParameter('alias1_field')->getValue());
960
        self::assertSame('value2', $qb->getParameter('alias2_field')->getValue());
961
        self::assertSame('value3', $qb->getParameter('alias2_field_2')->getValue());
962
    }
963
964
    /**
965
     * @group DDC-1933
966
     */
967
    public function testParametersAreCloned() : void
968
    {
969
        $originalQb = new QueryBuilder($this->em);
970
971
        $originalQb->setParameter('parameter1', 'value1');
972
973
        $copy = clone $originalQb;
974
        $copy->setParameter('parameter2', 'value2');
975
976
        self::assertCount(1, $originalQb->getParameters());
977
        self::assertSame('value1', $copy->getParameter('parameter1')->getValue());
978
        self::assertSame('value2', $copy->getParameter('parameter2')->getValue());
979
    }
980
981
    public function testGetRootAlias() : void
982
    {
983
        $qb = $this->em->createQueryBuilder()
984
            ->select('u')
985
            ->from(CmsUser::class, 'u');
986
987
        self::assertEquals('u', $qb->getRootAlias());
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\QueryBuilder::getRootAlias() has been deprecated: Please use $qb->getRootAliases() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

987
        self::assertEquals('u', /** @scrutinizer ignore-deprecated */ $qb->getRootAlias());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
988
    }
989
990
    public function testGetRootAliases() : void
991
    {
992
        $qb = $this->em->createQueryBuilder()
993
            ->select('u')
994
            ->from(CmsUser::class, 'u');
995
996
        self::assertEquals(['u'], $qb->getRootAliases());
997
    }
998
999
    public function testGetRootEntities() : void
1000
    {
1001
        $qb = $this->em->createQueryBuilder()
1002
            ->select('u')
1003
            ->from(CmsUser::class, 'u');
1004
1005
        self::assertEquals([CmsUser::class], $qb->getRootEntities());
1006
    }
1007
1008
    public function testGetSeveralRootAliases() : void
1009
    {
1010
        $qb = $this->em->createQueryBuilder()
1011
            ->select('u')
1012
            ->from(CmsUser::class, 'u')
1013
            ->from(CmsUser::class, 'u2');
1014
1015
        self::assertEquals(['u', 'u2'], $qb->getRootAliases());
1016
        self::assertEquals('u', $qb->getRootAlias());
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\QueryBuilder::getRootAlias() has been deprecated: Please use $qb->getRootAliases() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1016
        self::assertEquals('u', /** @scrutinizer ignore-deprecated */ $qb->getRootAlias());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1017
    }
1018
1019
    public function testBCAddJoinWithoutRootAlias() : void
1020
    {
1021
        $qb = $this->em->createQueryBuilder()
1022
            ->select('u')
1023
            ->from(CmsUser::class, 'u')
1024
            ->add('join', ['INNER JOIN u.groups g'], true);
1025
1026
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL());
1027
    }
1028
1029
    /**
1030
     * @group DDC-1211
1031
     */
1032
    public function testEmptyStringLiteral() : void
1033
    {
1034
        $expr = $this->em->getExpressionBuilder();
1035
        $qb   = $this->em->createQueryBuilder()
1036
            ->select('u')
1037
            ->from(CmsUser::class, 'u')
1038
            ->where($expr->eq('u.username', $expr->literal('')));
1039
1040
        self::assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL());
1041
    }
1042
1043
    /**
1044
     * @group DDC-1211
1045
     */
1046
    public function testEmptyNumericLiteral() : void
1047
    {
1048
        $expr = $this->em->getExpressionBuilder();
1049
        $qb   = $this->em->createQueryBuilder()
1050
            ->select('u')
1051
            ->from(CmsUser::class, 'u')
1052
            ->where($expr->eq('u.username', $expr->literal(0)));
1053
1054
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL());
1055
    }
1056
1057
    /**
1058
     * @group DDC-1227
1059
     */
1060
    public function testAddFromString() : void
1061
    {
1062
        $qb = $this->em->createQueryBuilder()
1063
            ->add('select', 'u')
0 ignored issues
show
Bug introduced by
'u' of type string is incompatible with the type array<mixed,mixed>|object expected by parameter $dqlPart of Doctrine\ORM\QueryBuilder::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1063
            ->add('select', /** @scrutinizer ignore-type */ 'u')
Loading history...
1064
            ->add('from', CmsUser::class . ' u');
1065
1066
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
1067
    }
1068
1069
    /**
1070
     * @group DDC-1619
1071
     */
1072
    public function testAddDistinct() : void
1073
    {
1074
        $qb = $this->em->createQueryBuilder()
1075
            ->select('u')
1076
            ->distinct()
1077
            ->from(CmsUser::class, 'u');
1078
1079
        self::assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
1080
    }
1081
1082
    /**
1083
     * @group DDC-2192
1084
     */
1085
    public function testWhereAppend() : void
1086
    {
1087
        $this->expectException(InvalidArgumentException::class);
1088
        $this->expectExceptionMessage("Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage.");
1089
1090
        $qb = $this->em->createQueryBuilder()
0 ignored issues
show
Unused Code introduced by
The assignment to $qb is dead and can be removed.
Loading history...
1091
            ->add('where', 'u.foo = ?1')
0 ignored issues
show
Bug introduced by
'u.foo = ?1' of type string is incompatible with the type array<mixed,mixed>|object expected by parameter $dqlPart of Doctrine\ORM\QueryBuilder::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1091
            ->add('where', /** @scrutinizer ignore-type */ 'u.foo = ?1')
Loading history...
1092
            ->add('where', 'u.bar = ?2', true);
1093
    }
1094
1095
    public function testSecondLevelCacheQueryBuilderOptions() : void
1096
    {
1097
        $defaultQueryBuilder = $this->em->createQueryBuilder()
1098
            ->select('s')
1099
            ->from(State::class, 's');
1100
1101
        self::assertFalse($defaultQueryBuilder->isCacheable());
1102
        self::assertEquals(0, $defaultQueryBuilder->getLifetime());
1103
        self::assertNull($defaultQueryBuilder->getCacheRegion());
1104
        self::assertNull($defaultQueryBuilder->getCacheMode());
1105
1106
        $defaultQuery = $defaultQueryBuilder->getQuery();
1107
1108
        self::assertFalse($defaultQuery->isCacheable());
1109
        self::assertEquals(0, $defaultQuery->getLifetime());
1110
        self::assertNull($defaultQuery->getCacheRegion());
1111
        self::assertNull($defaultQuery->getCacheMode());
1112
1113
        $builder = $this->em->createQueryBuilder()
1114
            ->select('s')
1115
            ->setLifetime(123)
1116
            ->setCacheable(true)
1117
            ->setCacheRegion('foo_reg')
1118
            ->setCacheMode(Cache::MODE_REFRESH)
1119
            ->from(State::class, 's');
1120
1121
        self::assertTrue($builder->isCacheable());
1122
        self::assertEquals(123, $builder->getLifetime());
1123
        self::assertEquals('foo_reg', $builder->getCacheRegion());
1124
        self::assertEquals(Cache::MODE_REFRESH, $builder->getCacheMode());
1125
1126
        $query = $builder->getQuery();
1127
1128
        self::assertTrue($query->isCacheable());
1129
        self::assertEquals(123, $query->getLifetime());
1130
        self::assertEquals('foo_reg', $query->getCacheRegion());
1131
        self::assertEquals(Cache::MODE_REFRESH, $query->getCacheMode());
1132
    }
1133
1134
    /**
1135
     * @group DDC-2253
1136
     */
1137
    public function testRebuildsFromParts() : void
1138
    {
1139
        $qb = $this->em->createQueryBuilder()
1140
          ->select('u')
1141
          ->from(CmsUser::class, 'u')
1142
          ->join('u.article', 'a');
1143
1144
        $dqlParts = $qb->getDQLParts();
1145
        $dql      = $qb->getDQL();
1146
1147
        $qb2 = $this->em->createQueryBuilder();
1148
        foreach (array_filter($dqlParts) as $name => $part) {
1149
            $qb2->add($name, $part);
1150
        }
1151
        $dql2 = $qb2->getDQL();
1152
1153
        self::assertEquals($dql, $dql2);
1154
    }
1155
1156
    public function testGetAllAliasesWithNoJoins() : void
1157
    {
1158
        $qb = $this->em->createQueryBuilder();
1159
        $qb->select('u')->from(CmsUser::class, 'u');
1160
1161
        $aliases = $qb->getAllAliases();
1162
1163
        self::assertEquals(['u'], $aliases);
1164
    }
1165
1166
    public function testGetAllAliasesWithJoins() : void
1167
    {
1168
        $qb = $this->em->createQueryBuilder()
1169
            ->select('u')
1170
            ->from(CmsUser::class, 'u')
1171
            ->join('u.groups', 'g');
1172
1173
        $aliases = $qb->getAllAliases();
1174
1175
        self::assertEquals(['u', 'g'], $aliases);
1176
    }
1177
1178
    /**
1179
     * @group 6699
1180
     */
1181
    public function testGetParameterTypeJuggling() : void
1182
    {
1183
        $builder = $this->em->createQueryBuilder()
1184
                            ->select('u')
1185
                            ->from(CmsUser::class, 'u')
1186
                            ->where('u.id = ?0');
1187
1188
        $builder->setParameter(0, 0);
1189
1190
        self::assertCount(1, $builder->getParameters());
1191
        self::assertSame(0, $builder->getParameter(0)->getValue());
1192
        self::assertSame(0, $builder->getParameter('0')->getValue());
1193
    }
1194
1195
    /**
1196
     * @group 6699
1197
     */
1198
    public function testSetParameterWithNameZeroIsNotOverridden() : void
1199
    {
1200
        $builder = $this->em->createQueryBuilder()
1201
                            ->select('u')
1202
                            ->from(CmsUser::class, 'u')
1203
                            ->where('u.id != ?0')
1204
                            ->andWhere('u.username = :name');
1205
1206
        $builder->setParameter(0, 0);
1207
        $builder->setParameter('name', 'Doctrine');
1208
1209
        self::assertCount(2, $builder->getParameters());
1210
        self::assertSame(0, $builder->getParameter('0')->getValue());
1211
        self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
1212
    }
1213
1214
    /**
1215
     * @group 6699
1216
     */
1217
    public function testSetParameterWithNameZeroDoesNotOverrideAnotherParameter() : void
1218
    {
1219
        $builder = $this->em->createQueryBuilder()
1220
                            ->select('u')
1221
                            ->from(CmsUser::class, 'u')
1222
                            ->where('u.id != ?0')
1223
                            ->andWhere('u.username = :name');
1224
1225
        $builder->setParameter('name', 'Doctrine');
1226
        $builder->setParameter(0, 0);
1227
1228
        self::assertCount(2, $builder->getParameters());
1229
        self::assertSame(0, $builder->getParameter(0)->getValue());
1230
        self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
1231
    }
1232
1233
    /**
1234
     * @group 6699
1235
     */
1236
    public function testSetParameterWithTypeJugglingWorks() : void
1237
    {
1238
        $builder = $this->em->createQueryBuilder()
1239
                            ->select('u')
1240
                            ->from(CmsUser::class, 'u')
1241
                            ->where('u.id != ?0')
1242
                            ->andWhere('u.username = :name');
1243
1244
        $builder->setParameter('0', 1);
1245
        $builder->setParameter('name', 'Doctrine');
1246
        $builder->setParameter(0, 2);
1247
        $builder->setParameter('0', 3);
1248
1249
        self::assertCount(2, $builder->getParameters());
1250
        self::assertSame(3, $builder->getParameter(0)->getValue());
1251
        self::assertSame(3, $builder->getParameter('0')->getValue());
1252
        self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
1253
    }
1254
}
1255