@@ 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 |
@@ 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 | { |