Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/Mouf/Database/MagicQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,13 @@ public function testTwig()
/**
* Removes all artifacts.
*/
private static function simplifySql($sql)
private static function simplifySql($sql, bool $stripBacktick = true)
{
$sql = str_replace("\n", ' ', $sql);
$sql = str_replace("\t", ' ', $sql);
$sql = str_replace('`', '', $sql);
if ($stripBacktick) {
$sql = str_replace('`', '', $sql);
}
$sql = str_replace(' ', ' ', $sql);
$sql = str_replace(' ', ' ', $sql);
$sql = str_replace(' ', ' ', $sql);
Expand Down Expand Up @@ -478,4 +480,15 @@ public function testPrepareStatementCache(): void
$this->assertEquals('SELECT * FROM users WHERE 0 <> 0', self::simplifySql($magicQuery->buildPreparedStatement('SELECT * FROM users WHERE id IN :users', ['users' => []])));
$this->assertEquals('SELECT * FROM users WHERE id IN (:users)', self::simplifySql($magicQuery->buildPreparedStatement('SELECT * FROM users WHERE id IN :users', ['users' => [1]])));
}

public function testBacktick(): void
{
$magicQuery = new MagicQuery(null, new ArrayCache());

$sql = "SELECT TIMESTAMPDIFF(SQL_TSI_SECOND, created_at, ended_at) FROM dual";
$this->assertEquals("SELECT TIMESTAMPDIFF(SQL_TSI_SECOND , `created_at`, `ended_at`) FROM `dual`", self::simplifySql($magicQuery->build($sql), false));

$sql = "SELECT TIMESTAMPDIFF(SECOND, created_at, ended_at) FROM dual";
$this->assertEquals("SELECT TIMESTAMPDIFF(SECOND , `created_at`, `ended_at`) FROM `dual`", self::simplifySql($magicQuery->build($sql), false));
}
}