Skip to content

Commit

Permalink
Make grammars macroable
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lundbøl <ml@napp.dk>
  • Loading branch information
Michael Lundbøl committed Jun 8, 2018
1 parent e9a7fe7 commit 40a1c71
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Database/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Illuminate\Database;

use Illuminate\Database\Query\Expression;
use Illuminate\Support\Traits\Macroable;

abstract class Grammar
{
use Macroable;

/**
* The grammar table prefix.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,18 @@ public function testDropAllTables()
$this->assertEquals('drop table `alpha`,`beta`,`gamma`', $statement);
}

public function testGrammarsAreMacroable()
{
// compileReplace macro.
$this->getGrammar()::macro('compileReplace', function () {
return true;
});

$c = $this->getGrammar()::compileReplace();

$this->assertTrue($c);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
Expand Down
12 changes: 12 additions & 0 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,16 @@ public function getGrammar()
{
return new \Illuminate\Database\Schema\Grammars\PostgresGrammar;
}

public function testGrammarsAreMacroable()
{
// compileReplace macro.
$this->getGrammar()::macro('compileReplace', function () {
return true;
});

$c = $this->getGrammar()::compileReplace();

$this->assertTrue($c);
}
}
12 changes: 12 additions & 0 deletions tests/Database/DatabaseSQLiteSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ public function testAddingMultiPolygon()
$this->assertEquals('alter table "geo" add column "coordinates" multipolygon not null', $statements[0]);
}

public function testGrammarsAreMacroable()
{
// compileReplace macro.
$this->getGrammar()::macro('compileReplace', function () {
return true;
});

$c = $this->getGrammar()::compileReplace();

$this->assertTrue($c);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
Expand Down
12 changes: 12 additions & 0 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,18 @@ public function testAddingMultiPolygon()
$this->assertEquals('alter table "geo" add "coordinates" geography not null', $statements[0]);
}

public function testGrammarsAreMacroable()
{
// compileReplace macro.
$this->getGrammar()::macro('compileReplace', function () {
return true;
});

$c = $this->getGrammar()::compileReplace();

$this->assertTrue($c);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
Expand Down

0 comments on commit 40a1c71

Please sign in to comment.