-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Add toRawSql, dumpRawSql() and ddRawSql() to Query Builders (#…
…47507) * [10.x] Add toRawSql, dumpRawSql() and ddRawSql() to Query Builders * styleci * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
1dd218f
commit 830efbe
Showing
10 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\MySqlGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseMySqlQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new MySqlGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->substituteBindingsIntoRawSql( | ||
'select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\PostgresGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabasePostgresQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new PostgresGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->substituteBindingsIntoRawSql( | ||
'select * from "users" where \'{}\' ?? \'Hello\\\'\\\'World?\' AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'{}\' ? \'Hello\\\'\\\'World?\' AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\SQLiteGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseSQLiteQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new SQLiteGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->substituteBindingsIntoRawSql( | ||
'select * from "users" where \'Hello\'\'World?\' IS NOT NULL AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'Hello\'\'World?\' IS NOT NULL AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\SqlServerGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseSqlServerQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new SqlServerGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->substituteBindingsIntoRawSql( | ||
"select * from [users] where 'Hello''World?' IS NOT NULL AND [email] = ?", | ||
['foo'], | ||
); | ||
|
||
$this->assertSame("select * from [users] where 'Hello''World?' IS NOT NULL AND [email] = 'foo'", $query); | ||
} | ||
} |