diff --git a/src/Illuminate/Database/Grammar.php b/src/Illuminate/Database/Grammar.php index 38525653292d..4c63413c3e4b 100755 --- a/src/Illuminate/Database/Grammar.php +++ b/src/Illuminate/Database/Grammar.php @@ -2,13 +2,10 @@ namespace Illuminate\Database; -use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Query\Expression; abstract class Grammar { - use Macroable; - /** * The grammar table prefix. * diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index 50af2276f3a5..76d65da3fbaa 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -5,10 +5,13 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Query\JsonExpression; class MySqlGrammar extends Grammar { + use Macroable; + /** * The grammar specific operators. * diff --git a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php index be5b882d6ac6..9ea8e4185186 100755 --- a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php @@ -5,9 +5,12 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Traits\Macroable; class PostgresGrammar extends Grammar { + use Macroable; + /** * All of the available clause operators. * diff --git a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php index 43ddec98443d..39b116c4d5ed 100755 --- a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php @@ -5,9 +5,12 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Traits\Macroable; class SQLiteGrammar extends Grammar { + use Macroable; + /** * The components that make up a select clause. * diff --git a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php index b2aff7b10fd2..79bf907bad2d 100755 --- a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php @@ -4,9 +4,12 @@ use Illuminate\Support\Arr; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Traits\Macroable; class SqlServerGrammar extends Grammar { + use Macroable; + /** * All of the available clause operators. * diff --git a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php index 2e5ec247ddfc..5014798016a1 100755 --- a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php @@ -4,10 +4,13 @@ use Illuminate\Support\Fluent; use Illuminate\Database\Connection; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Schema\Blueprint; class MySqlGrammar extends Grammar { + use Macroable; + /** * The possible column modifiers. * diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index e26be4f5f4e9..51a39aa61bf5 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -3,10 +3,13 @@ namespace Illuminate\Database\Schema\Grammars; use Illuminate\Support\Fluent; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Schema\Blueprint; class PostgresGrammar extends Grammar { + use Macroable; + /** * If this Grammar supports schema changes wrapped in a transaction. * diff --git a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php index d6ef59db42f1..784b61a374f7 100755 --- a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php @@ -7,10 +7,13 @@ use Illuminate\Support\Fluent; use Doctrine\DBAL\Schema\Index; use Illuminate\Database\Connection; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Schema\Blueprint; class SQLiteGrammar extends Grammar { + use Macroable; + /** * The possible column modifiers. * diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index 38f55fcf55ad..eee5b1be2a16 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -3,10 +3,13 @@ namespace Illuminate\Database\Schema\Grammars; use Illuminate\Support\Fluent; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Schema\Blueprint; class SqlServerGrammar extends Grammar { + use Macroable; + /** * If this Grammar supports schema changes wrapped in a transaction. * diff --git a/tests/Database/DatabaseGrammarTest.php b/tests/Database/DatabaseGrammarTest.php new file mode 100644 index 000000000000..abb307b96d85 --- /dev/null +++ b/tests/Database/DatabaseGrammarTest.php @@ -0,0 +1,66 @@ +assertSame(MySqlQueryGrammar::class, (new MySqlQueryGrammar())->compileReplace()); + $this->assertSame(SqlServerQueryGrammar::class, (new SqlServerQueryGrammar())->compileReplace()); + $this->assertSame(PostgresQueryGrammar::class, (new PostgresQueryGrammar())->compileReplace()); + $this->assertSame(SQLiteQueryGrammar::class, (new SQLiteQueryGrammar())->compileReplace()); + } + + public function testMacroableFunctionsAreUniquePerGrammarSchemaClass() + { + // compileReplace macro. + MySqlSchemaGrammar::macro('compileReplace', function () { + return MySqlSchemaGrammar::class; + }); + + SQLiteSchemaGrammar::macro('compileReplace', function () { + return SQLiteSchemaGrammar::class; + }); + + PostgresSchemaGrammar::macro('compileReplace', function () { + return PostgresSchemaGrammar::class; + }); + + SqlServerSchemaGrammar::macro('compileReplace', function () { + return SqlServerSchemaGrammar::class; + }); + + $this->assertSame(MySqlSchemaGrammar::class, (new MySqlSchemaGrammar())->compileReplace()); + $this->assertSame(SqlServerSchemaGrammar::class, (new SqlServerSchemaGrammar())->compileReplace()); + $this->assertSame(PostgresSchemaGrammar::class, (new PostgresSchemaGrammar())->compileReplace()); + $this->assertSame(SQLiteSchemaGrammar::class, (new SQLiteSchemaGrammar())->compileReplace()); + } +}