Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nio-dtp committed Dec 10, 2024
1 parent 19b6ad3 commit add32ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/SQL/Builder/WithSQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function buildSQL(CommonTableExpression $firstExpression, CommonTableExpr
foreach (array_merge([$firstExpression], $otherExpressions) as $part) {
$ctePart = [$part->name];
if ($part->columns !== null && count($part->columns) > 0) {
$ctePart[] = '(' . implode(', ', $part->columns) . ')';
$ctePart[] = ' (' . implode(', ', $part->columns) . ')';
}

$ctePart[] = ' AS (' . $part->query . ')';
Expand Down
19 changes: 4 additions & 15 deletions tests/Functional/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ public function testSelectWithCTENamedParameter(): void
self::markTestSkipped('The database platform does not support CTE.');
}

if (! $this->platformSupportsCTEColumnDefinition()) {
self::markTestSkipped('The database platform does not support CTE column definition.');
}

$expectedRows = $this->prepareExpectedRows([['virtual_id' => 1]]);
$qb = $this->connection->createQueryBuilder();

Expand All @@ -360,16 +356,12 @@ public function testSelectWithCTENamedParameter(): void
self::assertSame($expectedRows, $qb->executeQuery()->fetchAllAssociative());
}

public function testSelectWithCTEPositionalParametersBindForEachQuery(): void
public function testSelectWithCTEAndParametersBindForEachQuery(): void
{
if (! $this->platformSupportsCTEs()) {
self::markTestSkipped('The database platform does not support CTE.');
}

if (! $this->platformSupportsCTEColumnDefinition()) {
self::markTestSkipped('The database platform does not support CTE column definition.');
}

$expectedRows = $this->prepareExpectedRows([['virtual_id' => 1]]);
$qb = $this->connection->createQueryBuilder();

Expand All @@ -387,9 +379,11 @@ public function testSelectWithCTEPositionalParametersBindForEachQuery(): void

$qb->with('cte_a', $cteQueryBuilder1, ['virtual_id'])
->with('cte_b', $cteQueryBuilder2, ['virtual_id'])
->select('a.virtual_id')
->with('cte_c', 'SELECT 1 AS virtual_id')
->select('c.virtual_id')
->from('cte_a', 'a')
->join('a', 'cte_b', 'b', 'a.virtual_id = b.virtual_id')
->join('b', 'cte_c', 'c', 'b.virtual_id = c.virtual_id')
->where($qb->expr()->eq('a.virtual_id', '?'))
->setParameter(0, 1, ParameterType::INTEGER);

Expand Down Expand Up @@ -503,9 +497,4 @@ private function platformSupportsCTEs(): bool

return ! $platform instanceof MySQLPlatform || $platform instanceof MySQL80Platform;
}

private function platformSupportsCTEColumnDefinition(): bool
{
return $this->connection->getDatabasePlatform() instanceof SQLitePlatform;
}
}
2 changes: 1 addition & 1 deletion tests/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public function testSelectWithCTE(): void

self::assertEquals(
'WITH cte_a AS (SELECT ta.id, ta.name, ta.table_b_id FROM table_a ta WHERE ta.name LIKE :name)'
. ', cte_b(virtual_id, virtual_name) AS '
. ', cte_b (virtual_id, virtual_name) AS '
. '(SELECT ca.id AS virtual_id, ca.name AS virtual_name '
. 'FROM cte_a ca INNER JOIN table_b tb ON ca.table_b_id = tb.id) '
. 'SELECT cb.* FROM cte_b cb',
Expand Down

0 comments on commit add32ef

Please sign in to comment.