Code Duplication    Length = 11-14 lines in 14 locations

tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php 6 locations

@@ 13-24 (lines=12) @@
10
 */
11
class CountWalkerTest extends PaginationTestCase
12
{
13
    public function testCountQuery()
14
    {
15
        $query = $this->entityManager->createQuery(
16
            'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a');
17
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
18
        $query->setHint(CountWalker::HINT_DISTINCT, true);
19
        $query->setFirstResult(null)->setMaxResults(null);
20
21
        $this->assertEquals(
22
            "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL()
23
        );
24
    }
25
26
    public function testCountQuery_MixedResultsWithName()
27
    {
@@ 26-37 (lines=12) @@
23
        );
24
    }
25
26
    public function testCountQuery_MixedResultsWithName()
27
    {
28
        $query = $this->entityManager->createQuery(
29
            'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
30
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
31
        $query->setHint(CountWalker::HINT_DISTINCT, true);
32
        $query->setFirstResult(null)->setMaxResults(null);
33
34
        $this->assertEquals(
35
            "SELECT count(DISTINCT a0_.id) AS sclr_0 FROM Author a0_", $query->getSQL()
36
        );
37
    }
38
39
    public function testCountQuery_KeepsGroupBy()
40
    {
@@ 39-50 (lines=12) @@
36
        );
37
    }
38
39
    public function testCountQuery_KeepsGroupBy()
40
    {
41
        $query = $this->entityManager->createQuery(
42
            'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b GROUP BY b.id');
43
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
44
        $query->setHint(CountWalker::HINT_DISTINCT, true);
45
        $query->setFirstResult(null)->setMaxResults(null);
46
47
        $this->assertEquals(
48
            "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ GROUP BY b0_.id", $query->getSQL()
49
        );
50
    }
51
52
    public function testCountQuery_RemovesOrderBy()
53
    {
@@ 52-63 (lines=12) @@
49
        );
50
    }
51
52
    public function testCountQuery_RemovesOrderBy()
53
    {
54
        $query = $this->entityManager->createQuery(
55
            'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a ORDER BY a.name');
56
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
57
        $query->setHint(CountWalker::HINT_DISTINCT, true);
58
        $query->setFirstResult(null)->setMaxResults(null);
59
60
        $this->assertEquals(
61
            "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL()
62
        );
63
    }
64
65
    public function testCountQuery_RemovesLimits()
66
    {
@@ 65-76 (lines=12) @@
62
        );
63
    }
64
65
    public function testCountQuery_RemovesLimits()
66
    {
67
        $query = $this->entityManager->createQuery(
68
            'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a');
69
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
70
        $query->setHint(CountWalker::HINT_DISTINCT, true);
71
        $query->setFirstResult(null)->setMaxResults(null);
72
73
        $this->assertEquals(
74
            "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL()
75
        );
76
    }
77
78
    public function testCountQuery_HavingException()
79
    {
@@ 95-106 (lines=12) @@
92
    /**
93
     * Arbitrary Join
94
     */
95
    public function testCountQueryWithArbitraryJoin()
96
    {
97
        $query = $this->entityManager->createQuery(
98
            'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p LEFT JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c');
99
        $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
100
        $query->setHint(CountWalker::HINT_DISTINCT, true);
101
        $query->setFirstResult(null)->setMaxResults(null);
102
103
        $this->assertEquals(
104
            "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ LEFT JOIN Category c1_ ON (b0_.category_id = c1_.id)", $query->getSQL()
105
        );
106
    }
107
}
108
109

tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php 2 locations

@@ 34-44 (lines=11) @@
31
        );
32
    }
33
34
    public function testCountQuery_GroupBy(): void
35
    {
36
        $query = $this->entityManager->createQuery(
37
            'SELECT p.name FROM Doctrine\Tests\ORM\Tools\Pagination\Person p GROUP BY p.name');
38
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class);
39
        $query->setFirstResult(null)->setMaxResults(null);
40
41
        $this->assertSame(
42
            "SELECT COUNT(*) AS dctrn_count FROM (SELECT p0_.name AS name_0 FROM Person p0_ GROUP BY p0_.name) dctrn_table", $query->getSQL()
43
        );
44
    }
45
46
    public function testCountQuery_Having(): void
47
    {
@@ 46-56 (lines=11) @@
43
        );
44
    }
45
46
    public function testCountQuery_Having(): void
47
    {
48
        $query = $this->entityManager->createQuery(
49
            'SELECT g, u, count(u.id) AS userCount FROM Doctrine\Tests\ORM\Tools\Pagination\Group g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0');
50
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class);
51
        $query->setFirstResult(null)->setMaxResults(null);
52
53
        $this->assertSame(
54
            "SELECT COUNT(*) AS dctrn_count FROM (SELECT count(u0_.id) AS sclr_0, g1_.id AS id_1, u0_.id AS id_2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr_0 > 0) dctrn_table", $query->getSQL()
55
        );
56
    }
57
58
    public function testCountQueryOrderBySqlServer()
59
    {

tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php 6 locations

@@ 201-214 (lines=14) @@
198
    /**
199
     * @group DDC-3336
200
     */
201
    public function testCountQueryWithArithmeticOrderByCondition() : void
202
    {
203
        $query = $this->entityManager->createQuery(
204
            'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY (1 - 1000) * 1 DESC'
205
        );
206
        $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
207
208
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
209
210
        $this->assertSame(
211
            'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, (1 - 1000) * 1 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1 FROM Author a0_) dctrn_result_inner ORDER BY (1 - 1000) * 1 DESC) dctrn_result',
212
            $query->getSQL()
213
        );
214
    }
215
216
    public function testCountQueryWithComplexScalarOrderByItem() : void
217
    {
@@ 216-229 (lines=14) @@
213
        );
214
    }
215
216
    public function testCountQueryWithComplexScalarOrderByItem() : void
217
    {
218
        $query = $this->entityManager->createQuery(
219
            'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC'
220
        );
221
        $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
222
223
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
224
225
        $this->assertSame(
226
            'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_2 * image_width_3 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result_inner ORDER BY image_height_2 * image_width_3 DESC) dctrn_result',
227
            $query->getSQL()
228
        );
229
    }
230
231
    public function testCountQueryWithComplexScalarOrderByItemJoined() : void
232
    {
@@ 231-244 (lines=14) @@
228
        );
229
    }
230
231
    public function testCountQueryWithComplexScalarOrderByItemJoined() : void
232
    {
233
        $query = $this->entityManager->createQuery(
234
            'SELECT u FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.avatar a ORDER BY a.image_height * a.image_width DESC'
235
        );
236
        $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
237
238
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
239
240
        $this->assertSame(
241
            'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_1 * image_width_2 FROM (SELECT u0_.id AS id_0, a1_.image_height AS image_height_1, a1_.image_width AS image_width_2, a1_.user_id AS user_id_3 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result_inner ORDER BY image_height_1 * image_width_2 DESC) dctrn_result',
242
            $query->getSQL()
243
        );
244
    }
245
246
    public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() : void
247
    {
@@ 246-259 (lines=14) @@
243
        );
244
    }
245
246
    public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() : void
247
    {
248
        $query = $this->entityManager->createQuery(
249
            'SELECT u, partial a.{id, image_alt_desc} FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.avatar a ORDER BY a.image_height * a.image_width DESC'
250
        );
251
        $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
252
253
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
254
255
        $this->assertSame(
256
            'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_3 * image_width_4 FROM (SELECT u0_.id AS id_0, a1_.id AS id_1, a1_.image_alt_desc AS image_alt_desc_2, a1_.image_height AS image_height_3, a1_.image_width AS image_width_4, a1_.user_id AS user_id_5 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result_inner ORDER BY image_height_3 * image_width_4 DESC) dctrn_result',
257
            $query->getSQL()
258
        );
259
    }
260
261
    public function testCountQueryWithComplexScalarOrderByItemOracle() : void
262
    {
@@ 261-274 (lines=14) @@
258
        );
259
    }
260
261
    public function testCountQueryWithComplexScalarOrderByItemOracle() : void
262
    {
263
        $query = $this->entityManager->createQuery(
264
            'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC'
265
        );
266
        $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform());
267
268
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
269
270
        $this->assertSame(
271
            'SELECT DISTINCT ID_0, MIN(SCLR_5) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.image AS IMAGE_1, a0_.image_height AS IMAGE_HEIGHT_2, a0_.image_width AS IMAGE_WIDTH_3, a0_.image_alt_desc AS IMAGE_ALT_DESC_4, ROW_NUMBER() OVER(ORDER BY a0_.image_height * a0_.image_width DESC) AS SCLR_5, a0_.user_id AS USER_ID_6 FROM Avatar a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC',
272
            $query->getSQL()
273
        );
274
    }
275
276
    /**
277
     * @group DDC-3434
@@ 293-306 (lines=14) @@
290
        );
291
    }
292
293
    public function testLimitSubqueryWithColumnWithSortDirectionInName() : void
294
    {
295
        $query = $this->entityManager->createQuery(
296
            'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_alt_desc DESC'
297
        );
298
        $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
299
300
        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class);
301
302
        $this->assertSame(
303
            'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_alt_desc_4 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result_inner ORDER BY image_alt_desc_4 DESC) dctrn_result',
304
            $query->getSQL()
305
        );
306
    }
307
308
    public function testLimitSubqueryWithOrderByInnerJoined() : void
309
    {