Total Complexity | 43 |
Total Lines | 845 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Complex classes like QueryBuilderTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QueryBuilderTest, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
18 | class QueryBuilderTest extends AbstractTraitTestCase |
||
19 | { |
||
20 | use ReflectionTrait; |
||
21 | use QueryBuilderTrait; |
||
22 | |||
23 | const COMMAND_INVALID = 'INVALID'; |
||
24 | |||
25 | /** |
||
26 | * @var \ReflectionMethod[] |
||
27 | */ |
||
28 | private $abstractRepositoryPublicMethods = []; |
||
29 | |||
30 | /** |
||
31 | * @var AbstractRepository|\PHPUnit_Framework_MockObject_MockObject |
||
32 | */ |
||
33 | private $abstractRepository; |
||
34 | |||
35 | /** |
||
36 | * @var QueryBuilder |
||
37 | */ |
||
38 | private $queryBuilder; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @throws \Exception |
||
43 | */ |
||
44 | public function setUp() |
||
45 | { |
||
46 | if (empty($this->abstractRepositoryPublicMethods = $this->extractAbstractRepositoryPublicMethods())) { |
||
47 | throw new \Exception('There are no AbstractRepository public methods methods!'); |
||
48 | } |
||
49 | |||
50 | $this->abstractRepository = $this->getMockForAbstractClass( |
||
51 | AbstractRepository::class, |
||
52 | [], |
||
53 | '', |
||
54 | true, |
||
55 | true, |
||
56 | true, |
||
57 | $this->abstractRepositoryPublicMethods |
||
58 | ); |
||
59 | |||
60 | $this->queryBuilder = $this->createQueryBuilder($this->abstractRepository); |
||
61 | } |
||
62 | |||
63 | public function testQueryBuilderUsesTraits() |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @dataProvider crudData |
||
70 | * |
||
71 | * @param string $method |
||
72 | * @param bool $toString |
||
73 | */ |
||
74 | public function testCrud(string $method, bool $toString) |
||
75 | { |
||
76 | $this->abstractRepository->expects($this->once())->method($method)->with($this->queryBuilder, $toString); |
||
77 | $this->queryBuilder->$method($toString); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | public function crudData() |
||
85 | { |
||
86 | return \array_reduce( |
||
87 | [ |
||
88 | \array_map( |
||
89 | function ($publicMethod) { |
||
90 | return [ |
||
91 | $publicMethod, |
||
92 | false |
||
93 | ]; |
||
94 | }, |
||
95 | $this->extractAbstractRepositoryPublicMethods() |
||
96 | ), |
||
97 | \array_map( |
||
98 | function ($publicMethod) { |
||
99 | return [ |
||
100 | $publicMethod, |
||
101 | true |
||
102 | ]; |
||
103 | }, |
||
104 | $this->extractAbstractRepositoryPublicMethods() |
||
105 | ), |
||
106 | ], |
||
107 | 'array_merge', |
||
108 | [] |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @dataProvider buildQueryData |
||
114 | * |
||
115 | * @param string $command |
||
116 | * @param array $methods |
||
117 | * @param array $expected |
||
118 | * @param array $expectedToString |
||
119 | */ |
||
120 | public function testBuildQuery(string $command, array $methods, array $expected, array $expectedToString) |
||
121 | { |
||
122 | $this->addQueryPartsToQueryBuilder($command, $methods); |
||
123 | |||
124 | $this->assertEquals(\implode(' ', $expected), $this->queryBuilder->buildQuery()); |
||
125 | $this->assertEquals(\implode(' ', $expectedToString), $this->queryBuilder->toString()); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function buildQueryData() |
||
133 | { |
||
134 | /** phpcs:disable */ |
||
135 | return [ |
||
136 | [ |
||
137 | CommandEnum::INSERT_INTO, |
||
138 | [ |
||
139 | 'table' => 'table1', |
||
140 | 'value' => [ |
||
141 | 'table1.column1', |
||
142 | 'table1Column1Value', |
||
143 | ], |
||
144 | 'onDuplicateKeyUpdate' => [ |
||
145 | 'table1.column1', |
||
146 | 'table1Column1Value2', |
||
147 | ], |
||
148 | ], |
||
149 | [ |
||
150 | 'INSERT INTO', |
||
151 | 'table1', |
||
152 | '(table1.column1) VALUES (:Table1_Column1_Value)', |
||
153 | 'ON DUPLICATE KEY UPDATE table1.column1 = :Table1_Column1_OnDuplicateKeyUpdate', |
||
154 | ], |
||
155 | [ |
||
156 | 'INSERT INTO', |
||
157 | 'table1', |
||
158 | '(table1.column1) VALUES (\'table1Column1Value\')', |
||
159 | 'ON DUPLICATE KEY UPDATE table1.column1 = \'table1Column1Value2\'', |
||
160 | ], |
||
161 | ], |
||
162 | [ |
||
163 | CommandEnum::SELECT, |
||
164 | [ |
||
165 | 'column' => '*', |
||
166 | 'table' => 'table1', |
||
167 | 'innerJoin' => [ |
||
168 | 'table2', |
||
169 | 'table2.id = table1.table2_id AND table2.column1 = :bindValue2', |
||
170 | [ |
||
171 | 'bindValue2' => 2, |
||
172 | ], |
||
173 | ], |
||
174 | 'leftJoin' => [ |
||
175 | 'table3', |
||
176 | 'table3.id = table1.table3_id AND table3.column1 = :bindValue3', |
||
177 | [ |
||
178 | 'bindValue3' => 3, |
||
179 | ], |
||
180 | ], |
||
181 | 'rightJoin' => [ |
||
182 | 'table4', |
||
183 | 'table4.id = table1.table4_id AND table4.column1 = :bindValue4', |
||
184 | [ |
||
185 | 'bindValue4' => 4, |
||
186 | ], |
||
187 | ], |
||
188 | 'crossJoin' => [ |
||
189 | 'table5', |
||
190 | 'table5.id = table1.table5_id AND table5.column1 = :bindValue5', |
||
191 | [ |
||
192 | 'bindValue5' => 5, |
||
193 | ], |
||
194 | ], |
||
195 | 'fullOuterJoin' => [ |
||
196 | 'table6', |
||
197 | 'table6.id = table1.table6_id AND table6.column1 = :bindValue6', |
||
198 | [ |
||
199 | 'bindValue6' => 6, |
||
200 | ], |
||
201 | ], |
||
202 | 'innerJoinAs' => [ |
||
203 | 'table7', |
||
204 | 'table7_alias', |
||
205 | 'table7.id = table1.table7_id AND table7.column1 = :bindValue7', |
||
206 | [ |
||
207 | 'bindValue7' => 7, |
||
208 | ], |
||
209 | ], |
||
210 | 'leftJoinAs' => [ |
||
211 | 'table8', |
||
212 | 'table8_alias', |
||
213 | 'table8.id = table1.table8_id AND table8.column1 = :bindValue8', |
||
214 | [ |
||
215 | 'bindValue8' => 8, |
||
216 | ], |
||
217 | ], |
||
218 | 'rightJoinAs' => [ |
||
219 | 'table9', |
||
220 | 'table9_alias', |
||
221 | 'table9.id = table1.table9_id AND table9.column1 = :bindValue9', |
||
222 | [ |
||
223 | 'bindValue9' => 9, |
||
224 | ], |
||
225 | ], |
||
226 | 'crossJoinAs' => [ |
||
227 | 'table10', |
||
228 | 'table10_alias', |
||
229 | 'table10.id = table1.table10_id AND table10.column1 = :bindValue10', |
||
230 | [ |
||
231 | 'bindValue10' => 10, |
||
232 | ], |
||
233 | ], |
||
234 | 'fullOuterJoinAs' => [ |
||
235 | 'table11', |
||
236 | 'table11_alias', |
||
237 | 'table11.id = table1.table11_id AND table11.column1 = :bindValue11', |
||
238 | [ |
||
239 | 'bindValue11' => 11, |
||
240 | ], |
||
241 | ], |
||
242 | 'where' => [ |
||
243 | 'table1.column1 = :table1Column1BindValue', |
||
244 | [ |
||
245 | 'table1Column1BindValue' => 'table1Column1BindValue' |
||
246 | ] |
||
247 | ], |
||
248 | 'whereIn' => [ |
||
249 | 'table1.column2', |
||
250 | [ |
||
251 | 'table1Column2BindValue1', |
||
252 | 'table1Column2BindValue2', |
||
253 | ] |
||
254 | ], |
||
255 | 'whereNotIn' => [ |
||
256 | 'table1.column3', |
||
257 | [ |
||
258 | 'table1Column3BindValue1', |
||
259 | 'table1Column3BindValue2', |
||
260 | ] |
||
261 | ], |
||
262 | 'groupBy' => 'table1.column1', |
||
263 | 'having' => [ |
||
264 | 'table1.column1 = table2.column2 AND table1.column2 = :havingTable1Column2', |
||
265 | [ |
||
266 | 'havingTable1Column2' => 1.2, |
||
267 | ] |
||
268 | ], |
||
269 | 'orderBy' => [ |
||
270 | 'table1.column1', |
||
271 | KeywordEnum::DESC, |
||
272 | ], |
||
273 | 'limit' => 1, |
||
274 | 'offset' => 2, |
||
275 | ], |
||
276 | [ |
||
277 | 'SELECT', |
||
278 | '*', |
||
279 | 'FROM table1', |
||
280 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = :bindValue2)', |
||
281 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = :bindValue3)', |
||
282 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = :bindValue4)', |
||
283 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = :bindValue5)', |
||
284 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = :bindValue6)', |
||
285 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = :bindValue7)', |
||
286 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = :bindValue8)', |
||
287 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = :bindValue9)', |
||
288 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = :bindValue10)', |
||
289 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = :bindValue11)', |
||
290 | 'WHERE table1.column1 = :table1Column1BindValue', |
||
291 | 'AND table1.column2 IN (:0_table1column2_In, :1_table1column2_In)', |
||
292 | 'AND table1.column3 NOT IN (:0_table1column3_NotIn, :1_table1column3_NotIn)', |
||
293 | 'GROUP BY table1.column1', |
||
294 | 'HAVING table1.column1 = table2.column2 AND table1.column2 = :havingTable1Column2', |
||
295 | 'ORDER BY table1.column1 DESC', |
||
296 | 'LIMIT 1 OFFSET 2', |
||
297 | ], |
||
298 | [ |
||
299 | 'SELECT', |
||
300 | '*', |
||
301 | 'FROM table1', |
||
302 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = 2)', |
||
303 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = 3)', |
||
304 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = 4)', |
||
305 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = 5)', |
||
306 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = 6)', |
||
307 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = 7)', |
||
308 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = 8)', |
||
309 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = 9)', |
||
310 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = 10)', |
||
311 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = 11)', |
||
312 | 'WHERE table1.column1 = \'table1Column1BindValue\'', |
||
313 | 'AND table1.column2 IN (\'table1Column2BindValue1\', \'table1Column2BindValue2\')', |
||
314 | 'AND table1.column3 NOT IN (\'table1Column3BindValue1\', \'table1Column3BindValue2\')', |
||
315 | 'GROUP BY table1.column1', |
||
316 | 'HAVING table1.column1 = table2.column2 AND table1.column2 = 1.2', |
||
317 | 'ORDER BY table1.column1 DESC', |
||
318 | 'LIMIT 1 OFFSET 2', |
||
319 | ], |
||
320 | ], |
||
321 | [ |
||
322 | CommandEnum::SELECT, |
||
323 | [ |
||
324 | 'unionAll' => function () { |
||
325 | $queryBuilder = $this->createMock(QueryBuilderInterface::class); |
||
326 | $queryBuilder |
||
327 | ->method('commandData') |
||
|
|||
328 | ->willReturn(UnionTraitTest::QUERY_BUILDER_COMMAND) |
||
329 | ; |
||
330 | $queryBuilder |
||
331 | ->method('bindData') |
||
332 | ->willReturn(UnionTraitTest::QUERY_BUILDER_BIND_DATA) |
||
333 | ; |
||
334 | $queryBuilder |
||
335 | ->method('buildQuery') |
||
336 | ->willReturn(UnionTraitTest::QUERY_BUILDER_QUERY) |
||
337 | ; |
||
338 | |||
339 | return $queryBuilder; |
||
340 | }, |
||
341 | 'orderBy' => [ |
||
342 | 'col1', |
||
343 | KeywordEnum::DESC, |
||
344 | ], |
||
345 | 'limit' => 1, |
||
346 | 'offset' => 2, |
||
347 | ], |
||
348 | [ |
||
349 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = :col1 AND table1.col2 IS NOT NULL)', |
||
350 | 'UNION ALL', |
||
351 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = :col1 AND table1.col2 IS NOT NULL)', |
||
352 | 'UNION ALL', |
||
353 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = :col1 AND table1.col2 IS NOT NULL)', |
||
354 | 'ORDER BY col1 DESC', |
||
355 | 'LIMIT 1 OFFSET 2', |
||
356 | ], |
||
357 | [ |
||
358 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = \'val1\' AND table1.col2 IS NOT NULL)', |
||
359 | 'UNION ALL', |
||
360 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = \'val1\' AND table1.col2 IS NOT NULL)', |
||
361 | 'UNION ALL', |
||
362 | '(SELECT col1, col2, col3 FROM table1 WHERE table1.col1 = \'val1\' AND table1.col2 IS NOT NULL)', |
||
363 | 'ORDER BY col1 DESC', |
||
364 | 'LIMIT 1 OFFSET 2', |
||
365 | ], |
||
366 | ], |
||
367 | [ |
||
368 | CommandEnum::UPDATE, |
||
369 | [ |
||
370 | 'table' => 'table1', |
||
371 | 'set' => [ |
||
372 | 'table1.column1', |
||
373 | 'table1Column1Value', |
||
374 | ], |
||
375 | 'innerJoin' => [ |
||
376 | 'table2', |
||
377 | 'table2.id = table1.table2_id AND table2.column1 = :bindValue2', |
||
378 | [ |
||
379 | 'bindValue2' => 2, |
||
380 | ], |
||
381 | ], |
||
382 | 'leftJoin' => [ |
||
383 | 'table3', |
||
384 | 'table3.id = table1.table3_id AND table3.column1 = :bindValue3', |
||
385 | [ |
||
386 | 'bindValue3' => 3, |
||
387 | ], |
||
388 | ], |
||
389 | 'rightJoin' => [ |
||
390 | 'table4', |
||
391 | 'table4.id = table1.table4_id AND table4.column1 = :bindValue4', |
||
392 | [ |
||
393 | 'bindValue4' => 4, |
||
394 | ], |
||
395 | ], |
||
396 | 'crossJoin' => [ |
||
397 | 'table5', |
||
398 | 'table5.id = table1.table5_id AND table5.column1 = :bindValue5', |
||
399 | [ |
||
400 | 'bindValue5' => 5, |
||
401 | ], |
||
402 | ], |
||
403 | 'fullOuterJoin' => [ |
||
404 | 'table6', |
||
405 | 'table6.id = table1.table6_id AND table6.column1 = :bindValue6', |
||
406 | [ |
||
407 | 'bindValue6' => 6, |
||
408 | ], |
||
409 | ], |
||
410 | 'innerJoinAs' => [ |
||
411 | 'table7', |
||
412 | 'table7_alias', |
||
413 | 'table7.id = table1.table7_id AND table7.column1 = :bindValue7', |
||
414 | [ |
||
415 | 'bindValue7' => 7, |
||
416 | ], |
||
417 | ], |
||
418 | 'leftJoinAs' => [ |
||
419 | 'table8', |
||
420 | 'table8_alias', |
||
421 | 'table8.id = table1.table8_id AND table8.column1 = :bindValue8', |
||
422 | [ |
||
423 | 'bindValue8' => 8, |
||
424 | ], |
||
425 | ], |
||
426 | 'rightJoinAs' => [ |
||
427 | 'table9', |
||
428 | 'table9_alias', |
||
429 | 'table9.id = table1.table9_id AND table9.column1 = :bindValue9', |
||
430 | [ |
||
431 | 'bindValue9' => 9, |
||
432 | ], |
||
433 | ], |
||
434 | 'crossJoinAs' => [ |
||
435 | 'table10', |
||
436 | 'table10_alias', |
||
437 | 'table10.id = table1.table10_id AND table10.column1 = :bindValue10', |
||
438 | [ |
||
439 | 'bindValue10' => 10, |
||
440 | ], |
||
441 | ], |
||
442 | 'fullOuterJoinAs' => [ |
||
443 | 'table11', |
||
444 | 'table11_alias', |
||
445 | 'table11.id = table1.table11_id AND table11.column1 = :bindValue11', |
||
446 | [ |
||
447 | 'bindValue11' => 11, |
||
448 | ], |
||
449 | ], |
||
450 | 'where' => [ |
||
451 | 'table1.column1 = :table1Column1BindValue', |
||
452 | [ |
||
453 | 'table1Column1BindValue' => 'table1Column1BindValue' |
||
454 | ] |
||
455 | ], |
||
456 | 'whereIn' => [ |
||
457 | 'table1.column2', |
||
458 | [ |
||
459 | 'table1Column2BindValue1', |
||
460 | 'table1Column2BindValue2', |
||
461 | ] |
||
462 | ], |
||
463 | 'whereNotIn' => [ |
||
464 | 'table1.column3', |
||
465 | [ |
||
466 | 'table1Column3BindValue1', |
||
467 | 'table1Column3BindValue2', |
||
468 | ] |
||
469 | ], |
||
470 | 'limit' => 1, |
||
471 | 'offset' => 2, |
||
472 | ], |
||
473 | [ |
||
474 | 'UPDATE', |
||
475 | 'table1', |
||
476 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = :bindValue2)', |
||
477 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = :bindValue3)', |
||
478 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = :bindValue4)', |
||
479 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = :bindValue5)', |
||
480 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = :bindValue6)', |
||
481 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = :bindValue7)', |
||
482 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = :bindValue8)', |
||
483 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = :bindValue9)', |
||
484 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = :bindValue10)', |
||
485 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = :bindValue11)', |
||
486 | 'SET table1.column1 = :Table1_Column1_Update', |
||
487 | 'WHERE table1.column1 = :table1Column1BindValue', |
||
488 | 'AND table1.column2 IN (:0_table1column2_In, :1_table1column2_In)', |
||
489 | 'AND table1.column3 NOT IN (:0_table1column3_NotIn, :1_table1column3_NotIn)', |
||
490 | 'LIMIT 1 OFFSET 2' |
||
491 | ], |
||
492 | [ |
||
493 | 'UPDATE', |
||
494 | 'table1', |
||
495 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = 2)', |
||
496 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = 3)', |
||
497 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = 4)', |
||
498 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = 5)', |
||
499 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = 6)', |
||
500 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = 7)', |
||
501 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = 8)', |
||
502 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = 9)', |
||
503 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = 10)', |
||
504 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = 11)', |
||
505 | 'SET table1.column1 = \'table1Column1Value\'', |
||
506 | 'WHERE table1.column1 = \'table1Column1BindValue\'', |
||
507 | 'AND table1.column2 IN (\'table1Column2BindValue1\', \'table1Column2BindValue2\')', |
||
508 | 'AND table1.column3 NOT IN (\'table1Column3BindValue1\', \'table1Column3BindValue2\')', |
||
509 | 'LIMIT 1 OFFSET 2', |
||
510 | ], |
||
511 | ], |
||
512 | [ |
||
513 | CommandEnum::DELETE, |
||
514 | [ |
||
515 | 'table' => 'table1', |
||
516 | 'innerJoin' => [ |
||
517 | 'table2', |
||
518 | 'table2.id = table1.table2_id AND table2.column1 = :bindValue2', |
||
519 | [ |
||
520 | 'bindValue2' => 2, |
||
521 | ], |
||
522 | ], |
||
523 | 'leftJoin' => [ |
||
524 | 'table3', |
||
525 | 'table3.id = table1.table3_id AND table3.column1 = :bindValue3', |
||
526 | [ |
||
527 | 'bindValue3' => 3, |
||
528 | ], |
||
529 | ], |
||
530 | 'rightJoin' => [ |
||
531 | 'table4', |
||
532 | 'table4.id = table1.table4_id AND table4.column1 = :bindValue4', |
||
533 | [ |
||
534 | 'bindValue4' => 4, |
||
535 | ], |
||
536 | ], |
||
537 | 'crossJoin' => [ |
||
538 | 'table5', |
||
539 | 'table5.id = table1.table5_id AND table5.column1 = :bindValue5', |
||
540 | [ |
||
541 | 'bindValue5' => 5, |
||
542 | ], |
||
543 | ], |
||
544 | 'fullOuterJoin' => [ |
||
545 | 'table6', |
||
546 | 'table6.id = table1.table6_id AND table6.column1 = :bindValue6', |
||
547 | [ |
||
548 | 'bindValue6' => 6, |
||
549 | ], |
||
550 | ], |
||
551 | 'innerJoinAs' => [ |
||
552 | 'table7', |
||
553 | 'table7_alias', |
||
554 | 'table7.id = table1.table7_id AND table7.column1 = :bindValue7', |
||
555 | [ |
||
556 | 'bindValue7' => 7, |
||
557 | ], |
||
558 | ], |
||
559 | 'leftJoinAs' => [ |
||
560 | 'table8', |
||
561 | 'table8_alias', |
||
562 | 'table8.id = table1.table8_id AND table8.column1 = :bindValue8', |
||
563 | [ |
||
564 | 'bindValue8' => 8, |
||
565 | ], |
||
566 | ], |
||
567 | 'rightJoinAs' => [ |
||
568 | 'table9', |
||
569 | 'table9_alias', |
||
570 | 'table9.id = table1.table9_id AND table9.column1 = :bindValue9', |
||
571 | [ |
||
572 | 'bindValue9' => 9, |
||
573 | ], |
||
574 | ], |
||
575 | 'crossJoinAs' => [ |
||
576 | 'table10', |
||
577 | 'table10_alias', |
||
578 | 'table10.id = table1.table10_id AND table10.column1 = :bindValue10', |
||
579 | [ |
||
580 | 'bindValue10' => 10, |
||
581 | ], |
||
582 | ], |
||
583 | 'fullOuterJoinAs' => [ |
||
584 | 'table11', |
||
585 | 'table11_alias', |
||
586 | 'table11.id = table1.table11_id AND table11.column1 = :bindValue11', |
||
587 | [ |
||
588 | 'bindValue11' => 11, |
||
589 | ], |
||
590 | ], |
||
591 | 'where' => [ |
||
592 | 'table1.column1 = :table1Column1BindValue', |
||
593 | [ |
||
594 | 'table1Column1BindValue' => 'table1Column1BindValue' |
||
595 | ] |
||
596 | ], |
||
597 | 'whereIn' => [ |
||
598 | 'table1.column2', |
||
599 | [ |
||
600 | 'table1Column2BindValue1', |
||
601 | 'table1Column2BindValue2', |
||
602 | ] |
||
603 | ], |
||
604 | 'whereNotIn' => [ |
||
605 | 'table1.column3', |
||
606 | [ |
||
607 | 'table1Column3BindValue1', |
||
608 | 'table1Column3BindValue2', |
||
609 | ] |
||
610 | ], |
||
611 | 'limit' => 1, |
||
612 | 'offset' => 2, |
||
613 | ], |
||
614 | [ |
||
615 | 'DELETE', |
||
616 | 'table1 FROM table1', |
||
617 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = :bindValue2)', |
||
618 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = :bindValue3)', |
||
619 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = :bindValue4)', |
||
620 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = :bindValue5)', |
||
621 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = :bindValue6)', |
||
622 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = :bindValue7)', |
||
623 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = :bindValue8)', |
||
624 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = :bindValue9)', |
||
625 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = :bindValue10)', |
||
626 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = :bindValue11)', |
||
627 | 'WHERE table1.column1 = :table1Column1BindValue', |
||
628 | 'AND table1.column2 IN (:0_table1column2_In, :1_table1column2_In)', |
||
629 | 'AND table1.column3 NOT IN (:0_table1column3_NotIn, :1_table1column3_NotIn)', |
||
630 | 'LIMIT 1 OFFSET 2', |
||
631 | ], |
||
632 | [ |
||
633 | 'DELETE', |
||
634 | 'table1 FROM table1', |
||
635 | 'INNER JOIN table2 ON (table2.id = table1.table2_id AND table2.column1 = 2)', |
||
636 | 'LEFT JOIN table3 ON (table3.id = table1.table3_id AND table3.column1 = 3)', |
||
637 | 'RIGHT JOIN table4 ON (table4.id = table1.table4_id AND table4.column1 = 4)', |
||
638 | 'CROSS JOIN table5 ON (table5.id = table1.table5_id AND table5.column1 = 5)', |
||
639 | 'FULL OUTER JOIN table6 ON (table6.id = table1.table6_id AND table6.column1 = 6)', |
||
640 | 'INNER JOIN table7 AS table7_alias ON (table7.id = table1.table7_id AND table7.column1 = 7)', |
||
641 | 'LEFT JOIN table8 AS table8_alias ON (table8.id = table1.table8_id AND table8.column1 = 8)', |
||
642 | 'RIGHT JOIN table9 AS table9_alias ON (table9.id = table1.table9_id AND table9.column1 = 9)', |
||
643 | 'CROSS JOIN table10 AS table10_alias ON (table10.id = table1.table10_id AND table10.column1 = 10)', |
||
644 | 'FULL OUTER JOIN table11 AS table11_alias ON (table11.id = table1.table11_id AND table11.column1 = 11)', |
||
645 | 'WHERE table1.column1 = \'table1Column1BindValue\'', |
||
646 | 'AND table1.column2 IN (\'table1Column2BindValue1\', \'table1Column2BindValue2\')', |
||
647 | 'AND table1.column3 NOT IN (\'table1Column3BindValue1\', \'table1Column3BindValue2\')', |
||
648 | 'LIMIT 1 OFFSET 2', |
||
649 | ], |
||
650 | ], |
||
651 | ]; |
||
652 | /** phpcs:enable */ |
||
653 | } |
||
654 | |||
655 | /** |
||
656 | * @dataProvider buildQueryWithMissingQueryPartsProvideData |
||
657 | * |
||
658 | * @param string $command |
||
659 | * @param string[] $methods |
||
660 | * @param string $expectedException |
||
661 | * @param string $expectedExceptionMessage |
||
662 | */ |
||
663 | public function testBuildQueryWithMissingQueryPartsProvided( |
||
664 | string $command, |
||
665 | array $methods, |
||
666 | string $expectedException, |
||
667 | string $expectedExceptionMessage |
||
668 | ) { |
||
669 | $this->addQueryPartsToQueryBuilder($command, $methods); |
||
670 | |||
671 | $this->expectException($expectedException); |
||
672 | $this->expectExceptionMessage($expectedExceptionMessage); |
||
673 | |||
674 | $this->queryBuilder->buildQuery(); |
||
675 | } |
||
676 | |||
677 | /** |
||
678 | * @return array |
||
679 | */ |
||
680 | public function buildQueryWithMissingQueryPartsProvideData() |
||
740 | ], |
||
741 | ]; |
||
742 | } |
||
743 | |||
744 | public function testGetEntity() |
||
745 | { |
||
746 | /** @var EntityInterface $entity */ |
||
747 | $entity = $this->createMock(EntityInterface::class); |
||
748 | |||
749 | $queryBuilder = $this->createQueryBuilder($this->abstractRepository, $entity); |
||
750 | |||
751 | $this->assertTrue($queryBuilder->getEntity() instanceof EntityInterface); |
||
752 | } |
||
753 | |||
754 | /** |
||
755 | * @param string $command |
||
756 | * @param string[] $methods |
||
757 | * |
||
758 | * @return $this |
||
759 | */ |
||
760 | private function addQueryPartsToQueryBuilder(string $command, array $methods) |
||
823 | } |
||
824 | |||
825 | /** |
||
826 | * @return array |
||
827 | */ |
||
828 | private function extractAbstractRepositoryPublicMethods() |
||
863 | ) |
||
864 | )); |
||
865 | } |
||
866 | } |
||
867 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.