-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue: Added a call to the getValue method (#48652)
* Fixed issue: Added a call to the getValue method. Without this, raw SQL queries in conditions throw an exception. * Added check to prevent call on types other than Expression * Added new test cases for the modified method * Refactored the variable names * Fixed a StyleCI issue * Update Grammar.php --------- Co-authored-by: Bojan Lozo <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
616f81b
commit 6bfd755
Showing
2 changed files
with
46 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Query\Builder; | ||
use Illuminate\Database\Query\Expression; | ||
use Illuminate\Database\Query\Grammars\Grammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
|
||
class DatabaseQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testWhereRawReturnsStringWhenExpressionPassed() | ||
{ | ||
$builder = m::mock(Builder::class); | ||
$grammar = new Grammar; | ||
$reflection = new ReflectionClass($grammar); | ||
$method = $reflection->getMethod('whereRaw'); | ||
$expressionArray = ['sql' => new Expression('select * from "users"')]; | ||
|
||
$rawQuery = $method->invoke($grammar, $builder, $expressionArray); | ||
|
||
$this->assertSame('select * from "users"', $rawQuery); | ||
} | ||
|
||
public function testWhereRawReturnsStringWhenStringPassed() | ||
{ | ||
$builder = m::mock(Builder::class); | ||
$grammar = new Grammar; | ||
$reflection = new ReflectionClass($grammar); | ||
$method = $reflection->getMethod('whereRaw'); | ||
$stringArray = ['sql' => 'select * from "users"']; | ||
|
||
$rawQuery = $method->invoke($grammar, $builder, $stringArray); | ||
|
||
$this->assertSame('select * from "users"', $rawQuery); | ||
} | ||
} |