Failed Conditions
Pull Request — master (#8010)
by Oleg
08:41
created

QueryBuilderTest::testRequiredSelectExpr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 9
rs 10
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\Query\QueryException;
14
use Doctrine\ORM\QueryBuilder;
15
use Doctrine\Tests\Mocks\EntityManagerMock;
16
use Doctrine\Tests\Models\Cache\State;
17
use Doctrine\Tests\Models\CMS\CmsArticle;
18
use Doctrine\Tests\Models\CMS\CmsGroup;
19
use Doctrine\Tests\Models\CMS\CmsUser;
20
use Doctrine\Tests\OrmTestCase;
21
use InvalidArgumentException;
22
use function array_filter;
23
use function get_class;
24
25
/**
26
 * Test case for the QueryBuilder class used to build DQL query string in a
27
 * object oriented way.
28
 */
29
class QueryBuilderTest extends OrmTestCase
30
{
31
    /** @var EntityManagerMock */
32
    private $em;
33
34
    protected function setUp() : void
35
    {
36
        $this->em = $this->getTestEntityManager();
37
    }
38
39
    protected function assertValidQueryBuilder(QueryBuilder $qb, $expectedDql)
40
    {
41
        $dql = $qb->getDQL();
42
        $q   = $qb->getQuery();
0 ignored issues
show
Unused Code introduced by
The assignment to $q is dead and can be removed.
Loading history...
43
44
        self::assertEquals($expectedDql, $dql);
45
    }
46
47
    public function testSelectSetsType() : void
48
    {
49
        $qb = $this->em->createQueryBuilder()
50
            ->delete(CmsUser::class, 'u')
51
            ->select('u.id', 'u.username');
52
53
        self::assertEquals($qb->getType(), QueryBuilder::SELECT);
54
    }
55
56
    public function testEmptySelectSetsType() : void
57
    {
58
        $qb = $this->em->createQueryBuilder()
59
            ->delete(CmsUser::class, 'u')
60
            ->select();
61
62
        self::assertEquals($qb->getType(), QueryBuilder::SELECT);
63
    }
64
65
    public function testDeleteSetsType() : void
66
    {
67
        $qb = $this->em->createQueryBuilder()
68
            ->from(CmsUser::class, 'u')
69
            ->delete();
70
71
        self::assertEquals($qb->getType(), QueryBuilder::DELETE);
72
    }
73
74
    public function testUpdateSetsType() : void
75
    {
76
        $qb = $this->em->createQueryBuilder()
77
            ->from(CmsUser::class, 'u')
78
            ->update();
79
80
        self::assertEquals($qb->getType(), QueryBuilder::UPDATE);
81
    }
82
83
    public function testRequiredSelectExpr() : void
84
    {
85
        $this->expectException(QueryException::class);
86
        $this->expectExceptionMessage('SELECT expression is required for building DQL');
87
88
        $qb = $this->em->createQueryBuilder()
89
            ->from(CmsUser::class, 'u');
90
91
        $qb->getDQL();
92
    }
93
94
    public function testRequiredSelectDistinctExpr() : void
95
    {
96
        $this->expectException(QueryException::class);
97
        $this->expectExceptionMessage('SELECT expression is required for building DQL');
98
99
        $qb = $this->em->createQueryBuilder()
100
            ->distinct()
101
            ->from(CmsUser::class, 'u');
102
103
        $qb->getDQL();
104
    }
105
106
    public function testSimpleSelect() : void
107
    {
108
        $qb = $this->em->createQueryBuilder()
109
            ->from(CmsUser::class, 'u')
110
            ->select('u.id', 'u.username');
111
112
        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

112
        self::/** @scrutinizer ignore-call */ 
113
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
Loading history...
113
    }
114
115
    public function testSimpleDelete() : void
116
    {
117
        $qb = $this->em->createQueryBuilder()
118
            ->delete(CmsUser::class, 'u');
119
120
        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

120
        self::/** @scrutinizer ignore-call */ 
121
              assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u');
Loading history...
121
    }
122
123
    public function testSimpleSelectWithFromIndexBy() : void
124
    {
125
        $qb = $this->em->createQueryBuilder()
126
            ->from(CmsUser::class, 'u', 'u.id')
127
            ->select('u.id', 'u.username');
128
129
        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

129
        self::/** @scrutinizer ignore-call */ 
130
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
Loading history...
130
    }
131
132
    public function testSimpleSelectWithIndexBy() : void
133
    {
134
        $qb = $this->em->createQueryBuilder()
135
            ->from(CmsUser::class, 'u')
136
            ->indexBy('u', 'u.id')
137
            ->select('u.id', 'u.username');
138
139
        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

139
        self::/** @scrutinizer ignore-call */ 
140
              assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id');
Loading history...
140
    }
141
142
    public function testSimpleUpdate() : void
143
    {
144
        $qb = $this->em->createQueryBuilder()
145
            ->update(CmsUser::class, 'u')
146
            ->set('u.username', ':username');
147
148
        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

148
        self::/** @scrutinizer ignore-call */ 
149
              assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username');
Loading history...
149
    }
150
151
    public function testInnerJoin() : void
152
    {
153
        $qb = $this->em->createQueryBuilder()
154
            ->select('u', 'a')
155
            ->from(CmsUser::class, 'u')
156
            ->innerJoin('u.articles', 'a');
157
158
        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

158
        self::/** @scrutinizer ignore-call */ 
159
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a');
Loading history...
159
    }
160
161
    public function testComplexInnerJoin() : void
162
    {
163
        $qb = $this->em->createQueryBuilder()
164
            ->select('u', 'a')
165
            ->from(CmsUser::class, 'u')
166
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id');
167
168
        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

168
        self::/** @scrutinizer ignore-call */ 
169
              assertValidQueryBuilder(
Loading history...
169
            $qb,
170
            'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id'
171
        );
172
    }
173
174
    public function testComplexInnerJoinWithIndexBy() : void
175
    {
176
        $qb = $this->em->createQueryBuilder()
177
            ->select('u', 'a')
178
            ->from(CmsUser::class, 'u')
179
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id', 'a.name');
180
181
        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

181
        self::/** @scrutinizer ignore-call */ 
182
              assertValidQueryBuilder(
Loading history...
182
            $qb,
183
            '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'
184
        );
185
    }
186
187
    public function testLeftJoin() : void
188
    {
189
        $qb = $this->em->createQueryBuilder()
190
            ->select('u', 'a')
191
            ->from(CmsUser::class, 'u')
192
            ->leftJoin('u.articles', 'a');
193
194
        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

194
        self::/** @scrutinizer ignore-call */ 
195
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a');
Loading history...
195
    }
196
197
    public function testLeftJoinWithIndexBy() : void
198
    {
199
        $qb = $this->em->createQueryBuilder()
200
            ->select('u', 'a')
201
            ->from(CmsUser::class, 'u')
202
            ->leftJoin('u.articles', 'a', null, null, 'a.name');
203
204
        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

204
        self::/** @scrutinizer ignore-call */ 
205
              assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.name');
Loading history...
205
    }
206
207
    public function testMultipleFrom() : void
208
    {
209
        $qb = $this->em->createQueryBuilder()
210
            ->select('u', 'g')
211
            ->from(CmsUser::class, 'u')
212
            ->from(CmsGroup::class, 'g');
213
214
        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

214
        self::/** @scrutinizer ignore-call */ 
215
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g');
Loading history...
215
    }
216
217
    public function testMultipleFromWithIndexBy() : void
218
    {
219
        $qb = $this->em->createQueryBuilder()
220
            ->select('u', 'g')
221
            ->from(CmsUser::class, 'u')
222
            ->from(CmsGroup::class, 'g')
223
            ->indexBy('g', 'g.id');
224
225
        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

225
        self::/** @scrutinizer ignore-call */ 
226
              assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g INDEX BY g.id');
Loading history...
226
    }
227
228
    public function testMultipleFromWithJoin() : void
229
    {
230
        $qb = $this->em->createQueryBuilder()
231
            ->select('u', 'g')
232
            ->from(CmsUser::class, 'u')
233
            ->from(CmsGroup::class, 'g')
234
            ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id');
235
236
        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

236
        self::/** @scrutinizer ignore-call */ 
237
              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...
237
    }
238
239
    public function testMultipleFromWithMultipleJoin() : void
240
    {
241
        $qb = $this->em->createQueryBuilder()
242
            ->select('u', 'g')
243
            ->from(CmsUser::class, 'u')
244
            ->from(CmsArticle::class, 'a')
245
            ->innerJoin('u.groups', 'g')
246
            ->leftJoin('u.address', 'ad')
247
            ->innerJoin('a.comments', 'c');
248
249
        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

249
        self::/** @scrutinizer ignore-call */ 
250
              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...
250
    }
251
252
    public function testWhere() : void
253
    {
254
        $qb = $this->em->createQueryBuilder()
255
            ->select('u')
256
            ->from(CmsUser::class, 'u')
257
            ->where('u.id = :uid');
258
259
        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

259
        self::/** @scrutinizer ignore-call */ 
260
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid');
Loading history...
260
    }
261
262
    public function testComplexAndWhere() : void
263
    {
264
        $qb = $this->em->createQueryBuilder()
265
            ->select('u')
266
            ->from(CmsUser::class, 'u')
267
            ->where('u.id = :uid OR u.id = :uid2 OR u.id = :uid3')
268
            ->andWhere('u.name = :name');
269
270
        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

270
        self::/** @scrutinizer ignore-call */ 
271
              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...
271
    }
272
273
    public function testAndWhere() : void
274
    {
275
        $qb = $this->em->createQueryBuilder()
276
            ->select('u')
277
            ->from(CmsUser::class, 'u')
278
            ->where('u.id = :uid')
279
            ->andWhere('u.id = :uid2');
280
281
        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

281
        self::/** @scrutinizer ignore-call */ 
282
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
282
    }
283
284
    public function testOrWhere() : void
285
    {
286
        $qb = $this->em->createQueryBuilder()
287
            ->select('u')
288
            ->from(CmsUser::class, 'u')
289
            ->where('u.id = :uid')
290
            ->orWhere('u.id = :uid2');
291
292
        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

292
        self::/** @scrutinizer ignore-call */ 
293
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
Loading history...
293
    }
294
295
    public function testComplexAndWhereOrWhereNesting() : void
296
    {
297
        $qb = $this->em->createQueryBuilder();
298
        $qb->select('u')
299
           ->from(CmsUser::class, 'u')
300
           ->where('u.id = :uid')
301
           ->orWhere('u.id = :uid2')
302
           ->andWhere('u.id = :uid3')
303
           ->orWhere('u.name = :name1', 'u.name = :name2')
304
           ->andWhere('u.name <> :noname');
305
306
        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

306
        self::/** @scrutinizer ignore-call */ 
307
              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...
307
    }
308
309
    public function testAndWhereIn() : void
310
    {
311
        $qb = $this->em->createQueryBuilder();
312
        $qb->select('u')
313
           ->from(CmsUser::class, 'u')
314
           ->where('u.id = :uid')
315
           ->andWhere($qb->expr()->in('u.id', [1, 2, 3]));
316
317
        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

317
        self::/** @scrutinizer ignore-call */ 
318
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id IN(1, 2, 3)');
Loading history...
318
    }
319
320
    public function testOrWhereIn() : void
321
    {
322
        $qb = $this->em->createQueryBuilder();
323
        $qb->select('u')
324
           ->from(CmsUser::class, 'u')
325
           ->where('u.id = :uid')
326
           ->orWhere($qb->expr()->in('u.id', [1, 2, 3]));
327
328
        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

328
        self::/** @scrutinizer ignore-call */ 
329
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id IN(1, 2, 3)');
Loading history...
329
    }
330
331
    public function testAndWhereNotIn() : void
332
    {
333
        $qb = $this->em->createQueryBuilder();
334
        $qb->select('u')
335
           ->from(CmsUser::class, 'u')
336
           ->where('u.id = :uid')
337
           ->andWhere($qb->expr()->notIn('u.id', [1, 2, 3]));
338
339
        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

339
        self::/** @scrutinizer ignore-call */ 
340
              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...
340
    }
341
342
    public function testOrWhereNotIn() : void
343
    {
344
        $qb = $this->em->createQueryBuilder();
345
        $qb->select('u')
346
           ->from(CmsUser::class, 'u')
347
           ->where('u.id = :uid')
348
           ->orWhere($qb->expr()->notIn('u.id', [1, 2, 3]));
349
350
        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

350
        self::/** @scrutinizer ignore-call */ 
351
              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...
351
    }
352
353
    public function testGroupBy() : void
354
    {
355
        $qb = $this->em->createQueryBuilder()
356
            ->select('u')
357
            ->from(CmsUser::class, 'u')
358
            ->groupBy('u.id')
359
            ->addGroupBy('u.username');
360
361
        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

361
        self::/** @scrutinizer ignore-call */ 
362
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id, u.username');
Loading history...
362
    }
363
364
    public function testHaving() : void
365
    {
366
        $qb = $this->em->createQueryBuilder()
367
            ->select('u')
368
            ->from(CmsUser::class, 'u')
369
            ->groupBy('u.id')
370
            ->having('COUNT(u.id) > 1');
371
372
        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

372
        self::/** @scrutinizer ignore-call */ 
373
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1');
Loading history...
373
    }
374
375
    public function testAndHaving() : void
376
    {
377
        $qb = $this->em->createQueryBuilder()
378
            ->select('u')
379
            ->from(CmsUser::class, 'u')
380
            ->groupBy('u.id')
381
            ->having('COUNT(u.id) > 1')
382
            ->andHaving('COUNT(u.id) < 1');
383
384
        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

384
        self::/** @scrutinizer ignore-call */ 
385
              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...
385
    }
386
387
    public function testOrHaving() : void
388
    {
389
        $qb = $this->em->createQueryBuilder()
390
            ->select('u')
391
            ->from(CmsUser::class, 'u')
392
            ->groupBy('u.id')
393
            ->having('COUNT(u.id) > 1')
394
            ->andHaving('COUNT(u.id) < 1')
395
            ->orHaving('COUNT(u.id) > 1');
396
397
        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

397
        self::/** @scrutinizer ignore-call */ 
398
              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...
398
    }
399
400
    public function testOrderBy() : void
401
    {
402
        $qb = $this->em->createQueryBuilder()
403
            ->select('u')
404
            ->from(CmsUser::class, 'u')
405
            ->orderBy('u.username', 'ASC');
406
407
        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

407
        self::/** @scrutinizer ignore-call */ 
408
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
Loading history...
408
    }
409
410
    public function testOrderByWithExpression() : void
411
    {
412
        $qb = $this->em->createQueryBuilder();
413
        $qb->select('u')
414
            ->from(CmsUser::class, 'u')
415
            ->orderBy($qb->expr()->asc('u.username'));
416
417
        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

417
        self::/** @scrutinizer ignore-call */ 
418
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC');
Loading history...
418
    }
419
420
    public function testAddOrderBy() : void
421
    {
422
        $qb = $this->em->createQueryBuilder()
423
            ->select('u')
424
            ->from(CmsUser::class, 'u')
425
            ->orderBy('u.username', 'ASC')
426
            ->addOrderBy('u.username', 'DESC');
427
428
        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

428
        self::/** @scrutinizer ignore-call */ 
429
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC');
Loading history...
429
    }
430
431
    public function testAddOrderByWithExpression() : void
432
    {
433
        $qb = $this->em->createQueryBuilder();
434
        $qb->select('u')
435
            ->from(CmsUser::class, 'u')
436
            ->orderBy('u.username', 'ASC')
437
            ->addOrderBy($qb->expr()->desc('u.username'));
438
439
        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

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

696
        self::/** @scrutinizer ignore-call */ 
697
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
697
    }
698
699
    public function testMultipleAndWhere() : void
700
    {
701
        $qb = $this->em->createQueryBuilder()
702
            ->select('u')
703
            ->from(CmsUser::class, 'u')
704
            ->andWhere('u.id = :uid', 'u.id = :uid2');
705
706
        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

706
        self::/** @scrutinizer ignore-call */ 
707
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2');
Loading history...
707
    }
708
709
    public function testMultipleOrWhere() : void
710
    {
711
        $qb = $this->em->createQueryBuilder();
712
        $qb->select('u')
713
           ->from(CmsUser::class, 'u')
714
           ->orWhere('u.id = :uid', $qb->expr()->eq('u.id', ':uid2'));
715
716
        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

716
        self::/** @scrutinizer ignore-call */ 
717
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2');
Loading history...
717
    }
718
719
    public function testComplexWhere() : void
720
    {
721
        $qb     = $this->em->createQueryBuilder();
722
        $orExpr = $qb->expr()->orX();
723
        $orExpr->add($qb->expr()->eq('u.id', ':uid3'));
724
        $orExpr->add($qb->expr()->in('u.id', [1]));
725
726
        $qb->select('u')
727
           ->from(CmsUser::class, 'u')
728
           ->where($orExpr);
729
730
        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

730
        self::/** @scrutinizer ignore-call */ 
731
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR u.id IN(1)');
Loading history...
731
    }
732
733
    public function testWhereInWithStringLiterals() : void
734
    {
735
        $qb = $this->em->createQueryBuilder();
736
        $qb->select('u')
737
           ->from(CmsUser::class, 'u')
738
           ->where($qb->expr()->in('u.name', ['one', 'two', 'three']));
739
740
        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

740
        self::/** @scrutinizer ignore-call */ 
741
              assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
Loading history...
741
742
        $qb->where($qb->expr()->in('u.name', ["O'Reilly", "O'Neil", 'Smith']));
743
744
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')");
745
    }
746
747
    public function testWhereInWithObjectLiterals() : void
748
    {
749
        $qb   = $this->em->createQueryBuilder();
750
        $expr = $this->em->getExpressionBuilder();
751
        $qb->select('u')
752
           ->from(CmsUser::class, 'u')
753
           ->where($expr->in('u.name', [$expr->literal('one'), $expr->literal('two'), $expr->literal('three')]));
754
755
        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

755
        self::/** @scrutinizer ignore-call */ 
756
              assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')");
Loading history...
756
757
        $qb->where($expr->in('u.name', [$expr->literal("O'Reilly"), $expr->literal("O'Neil"), $expr->literal('Smith')]));
758
759
        self::assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')");
760
    }
761
762
    public function testNegation() : void
763
    {
764
        $expr   = $this->em->getExpressionBuilder();
765
        $orExpr = $expr->orX();
766
        $orExpr->add($expr->eq('u.id', ':uid3'));
767
        $orExpr->add($expr->not($expr->in('u.id', [1])));
768
769
        $qb = $this->em->createQueryBuilder();
770
        $qb->select('u')
771
           ->from(CmsUser::class, 'u')
772
           ->where($orExpr);
773
774
        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

774
        self::/** @scrutinizer ignore-call */ 
775
              assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR NOT(u.id IN(1))');
Loading history...
775
    }
776
777
    public function testSomeAllAny() : void
778
    {
779
        $qb   = $this->em->createQueryBuilder();
780
        $expr = $this->em->getExpressionBuilder();
781
782
        $qb->select('u')
783
           ->from(CmsUser::class, 'u')
784
           ->where($expr->gt('u.id', $expr->all('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a')));
785
786
        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

786
        self::/** @scrutinizer ignore-call */ 
787
              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...
787
    }
788
789
    public function testMultipleIsolatedQueryConstruction() : void
790
    {
791
        $qb   = $this->em->createQueryBuilder();
792
        $expr = $this->em->getExpressionBuilder();
793
794
        $qb->select('u')->from(CmsUser::class, 'u');
795
        $qb->where($expr->eq('u.name', ':name'));
796
        $qb->setParameter('name', 'romanb');
797
798
        $q1 = $qb->getQuery();
799
800
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name', $q1->getDQL());
801
        self::assertCount(1, $q1->getParameters());
802
803
        // add another condition and construct a second query
804
        $qb->andWhere($expr->eq('u.id', ':id'));
805
        $qb->setParameter('id', 42);
806
807
        $q2 = $qb->getQuery();
808
809
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name AND u.id = :id', $q2->getDQL());
810
        self::assertNotSame($q1, $q2); // two different, independent queries
811
        self::assertCount(2, $q2->getParameters());
812
        self::assertCount(1, $q1->getParameters()); // $q1 unaffected
813
    }
814
815
    public function testGetEntityManager() : void
816
    {
817
        $qb = $this->em->createQueryBuilder();
818
        self::assertEquals($this->em->getWrappedEntityManager(), $qb->getEntityManager());
819
    }
820
821
    public function testInitialStateIsClean() : void
822
    {
823
        $qb = $this->em->createQueryBuilder();
824
        self::assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
825
    }
826
827
    public function testAlteringQueryChangesStateToDirty() : void
828
    {
829
        $qb = $this->em->createQueryBuilder()
830
            ->select('u')
831
            ->from(CmsUser::class, 'u');
832
833
        self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
834
    }
835
836
    public function testSelectWithFuncExpression() : void
837
    {
838
        $qb   = $this->em->createQueryBuilder();
839
        $expr = $qb->expr();
840
        $qb->select($expr->count('e.id'));
841
842
        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

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

994
        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...
995
    }
996
997
    public function testGetRootAliases() : void
998
    {
999
        $qb = $this->em->createQueryBuilder()
1000
            ->select('u')
1001
            ->from(CmsUser::class, 'u');
1002
1003
        self::assertEquals(['u'], $qb->getRootAliases());
1004
    }
1005
1006
    public function testGetRootEntities() : void
1007
    {
1008
        $qb = $this->em->createQueryBuilder()
1009
            ->select('u')
1010
            ->from(CmsUser::class, 'u');
1011
1012
        self::assertEquals([CmsUser::class], $qb->getRootEntities());
1013
    }
1014
1015
    public function testGetSeveralRootAliases() : void
1016
    {
1017
        $qb = $this->em->createQueryBuilder()
1018
            ->select('u')
1019
            ->from(CmsUser::class, 'u')
1020
            ->from(CmsUser::class, 'u2');
1021
1022
        self::assertEquals(['u', 'u2'], $qb->getRootAliases());
1023
        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

1023
        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...
1024
    }
1025
1026
    public function testBCAddJoinWithoutRootAlias() : void
1027
    {
1028
        $qb = $this->em->createQueryBuilder()
1029
            ->select('u')
1030
            ->from(CmsUser::class, 'u')
1031
            ->add('join', ['INNER JOIN u.groups g'], true);
1032
1033
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL());
1034
    }
1035
1036
    /**
1037
     * @group DDC-1211
1038
     */
1039
    public function testEmptyStringLiteral() : void
1040
    {
1041
        $expr = $this->em->getExpressionBuilder();
1042
        $qb   = $this->em->createQueryBuilder()
1043
            ->select('u')
1044
            ->from(CmsUser::class, 'u')
1045
            ->where($expr->eq('u.username', $expr->literal('')));
1046
1047
        self::assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL());
1048
    }
1049
1050
    /**
1051
     * @group DDC-1211
1052
     */
1053
    public function testEmptyNumericLiteral() : void
1054
    {
1055
        $expr = $this->em->getExpressionBuilder();
1056
        $qb   = $this->em->createQueryBuilder()
1057
            ->select('u')
1058
            ->from(CmsUser::class, 'u')
1059
            ->where($expr->eq('u.username', $expr->literal(0)));
1060
1061
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL());
1062
    }
1063
1064
    /**
1065
     * @group DDC-1227
1066
     */
1067
    public function testAddFromString() : void
1068
    {
1069
        $qb = $this->em->createQueryBuilder()
1070
            ->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

1070
            ->add('select', /** @scrutinizer ignore-type */ 'u')
Loading history...
1071
            ->add('from', CmsUser::class . ' u');
1072
1073
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
1074
    }
1075
1076
    /**
1077
     * @group DDC-1619
1078
     */
1079
    public function testAddDistinct() : void
1080
    {
1081
        $qb = $this->em->createQueryBuilder()
1082
            ->select('u')
1083
            ->distinct()
1084
            ->from(CmsUser::class, 'u');
1085
1086
        self::assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
1087
    }
1088
1089
    /**
1090
     * @group DDC-2192
1091
     */
1092
    public function testWhereAppend() : void
1093
    {
1094
        $this->expectException(InvalidArgumentException::class);
1095
        $this->expectExceptionMessage("Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage.");
1096
1097
        $qb = $this->em->createQueryBuilder()
0 ignored issues
show
Unused Code introduced by
The assignment to $qb is dead and can be removed.
Loading history...
1098
            ->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

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