Skip to content

Commit

Permalink
Merge branch 'master' into logger-context
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jan 20, 2024
2 parents 49a5a07 + 38c9090 commit dfb135c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
53 changes: 29 additions & 24 deletions tests/AbstractQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ public function testBuildCondition(
[$sql, $params] = $db->getQueryBuilder()->build($query);
$replacedQuotes = DbHelper::replaceQuotes((string) $expected, $db->getDriverName());
$this->assertIsString($replacedQuotes);
$this->assertEquals('SELECT *' . (empty($expected) ? '' : ' WHERE ' . $replacedQuotes), $sql);
$this->assertEquals(
'SELECT *'
. ($db->getDriverName() === 'oci' ? ' FROM DUAL' : '')
. (empty($expected) ? '' : ' WHERE ' . DbHelper::replaceQuotes($expected, $db->getDriverName())),
$sql
);
$this->assertEquals($expectedParams, $params);
}
Expand Down Expand Up @@ -349,9 +351,9 @@ public function testBuildFilterCondition(array $condition, string $expected, arr
[$sql, $params] = $qb->build($query);
$this->assertSame(
'SELECT *' . (
empty($expected) ? '' : ' WHERE ' . DbHelper::replaceQuotes($expected, $db->getDriverName())
),
'SELECT *'
. ($db->getDriverName() === 'oci' ? ' FROM DUAL' : '')
. (empty($expected) ? '' : ' WHERE ' . DbHelper::replaceQuotes($expected, $db->getDriverName())),
$sql,
);
$this->assertSame($expectedParams, $params);
Expand Down Expand Up @@ -472,10 +474,12 @@ public function testBuildLikeCondition(
[$sql, $params] = $db->getQueryBuilder()->build($query);
$replacedQuotes = DbHelper::replaceQuotes($expected, $db->getDriverName());
$this->assertIsString($replacedQuotes);
$this->assertSame('SELECT *' . (empty($expected) ? '' : ' WHERE ' . $replacedQuotes), $sql);
$this->assertSame(
'SELECT *'
. ($db->getDriverName() === 'oci' ? ' FROM DUAL' : '')
. (empty($expected) ? '' : ' WHERE ' . DbHelper::replaceQuotes($expected, $db->getDriverName())),
$sql
);
$this->assertSame($expectedParams, $params);
}
Expand Down Expand Up @@ -1306,12 +1310,13 @@ public function testBuildWithSelectOption(): void
[$sql, $params] = $qb->build($query);
$this->assertSame(
<<<SQL
SELECT DISTINCT *
SQL,
$sql,
);
$expected = 'SELECT DISTINCT *';
if ($this->getDriverName() === 'oci') {
$expected .= ' FROM DUAL';
}
$this->assertSame($expected, $sql);
$this->assertSame([], $params);
}
Expand Down Expand Up @@ -1558,16 +1563,16 @@ public function testCreateIndex(string $sql, Closure $builder): void
public function testCreateView(): void
{
$db = $this->getConnection();
$qb = $db->getQueryBuilder();
$expected = 'CREATE VIEW [[animal_view]] AS SELECT [[1]]';
if ($this->getDriverName() === 'oci') {
$expected .= ' FROM DUAL';
}
$this->assertSame(
DbHelper::replaceQuotes(
<<<SQL
CREATE VIEW [[animal_view]] AS SELECT [[1]]
SQL,
$db->getDriverName(),
),
DbHelper::replaceQuotes($expected, $db->getDriverName()),
$qb->createView('animal_view', (new query($db))->select('1')),
);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Common/CommonQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ public function testWithQueryRecursive()

$db->close();
}

public function testSelectWithoutFrom()
{
$db = $this->getConnection();

$query = (new Query($db))->select(new Expression('1'));

$this->assertEquals(1, $query->scalar());

$db->close();
}
}

0 comments on commit dfb135c

Please sign in to comment.