From d30930165c89d9d4e20a8bfb187d2eddcc32ff16 Mon Sep 17 00:00:00 2001 From: Roman Nix Date: Fri, 13 Nov 2020 17:29:11 +0700 Subject: [PATCH 1/2] add path to post create hooks in MigrationCreator --- .../Database/Migrations/MigrationCreator.php | 7 ++++--- tests/Database/DatabaseMigrationCreatorTest.php | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Database/Migrations/MigrationCreator.php b/src/Illuminate/Database/Migrations/MigrationCreator.php index a79039a7a20b..2f6d415718b3 100755 --- a/src/Illuminate/Database/Migrations/MigrationCreator.php +++ b/src/Illuminate/Database/Migrations/MigrationCreator.php @@ -74,7 +74,7 @@ public function create($name, $path, $table = null, $create = false) // Next, we will fire any hooks that are supposed to fire after a migration is // created. Once that is done we'll be ready to return the full path to the // migration file so it can be used however it's needed by the developer. - $this->firePostCreateHooks($table); + $this->firePostCreateHooks($table, $path); return $path; } @@ -184,12 +184,13 @@ protected function getPath($name, $path) * Fire the registered post create hooks. * * @param string|null $table + * @param string $path * @return void */ - protected function firePostCreateHooks($table) + protected function firePostCreateHooks($table, $path) { foreach ($this->postCreate as $callback) { - $callback($table); + $callback($table, $path); } } diff --git a/tests/Database/DatabaseMigrationCreatorTest.php b/tests/Database/DatabaseMigrationCreatorTest.php index e262443c697e..491be54c3eba 100755 --- a/tests/Database/DatabaseMigrationCreatorTest.php +++ b/tests/Database/DatabaseMigrationCreatorTest.php @@ -35,9 +35,11 @@ public function testBasicCreateMethodCallsPostCreateHooks() $table = 'baz'; $creator = $this->getCreator(); - unset($_SERVER['__migration.creator']); - $creator->afterCreate(function ($table) { - $_SERVER['__migration.creator'] = $table; + unset($_SERVER['__migration.creator.table']); + unset($_SERVER['__migration.creator.path']); + $creator->afterCreate(function ($table, $path) { + $_SERVER['__migration.creator.table'] = $table; + $_SERVER['__migration.creator.path'] = $path; }); $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo'); @@ -50,9 +52,11 @@ public function testBasicCreateMethodCallsPostCreateHooks() $creator->create('create_bar', 'foo', $table); - $this->assertEquals($_SERVER['__migration.creator'], $table); + $this->assertEquals($_SERVER['__migration.creator.table'], $table); + $this->assertEquals($_SERVER['__migration.creator.path'], 'foo/foo_create_bar.php'); - unset($_SERVER['__migration.creator']); + unset($_SERVER['__migration.creator.table']); + unset($_SERVER['__migration.creator.path']); } public function testTableUpdateMigrationStoresMigrationFile() From 5222e5086fd555afa8f845e03a1151b05f87344a Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 13 Nov 2020 11:33:57 +0100 Subject: [PATCH 2/2] Update MigrationCreator.php --- src/Illuminate/Database/Migrations/MigrationCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Migrations/MigrationCreator.php b/src/Illuminate/Database/Migrations/MigrationCreator.php index 2f6d415718b3..78223f7dff4d 100755 --- a/src/Illuminate/Database/Migrations/MigrationCreator.php +++ b/src/Illuminate/Database/Migrations/MigrationCreator.php @@ -184,7 +184,7 @@ protected function getPath($name, $path) * Fire the registered post create hooks. * * @param string|null $table - * @param string $path + * @param string $path * @return void */ protected function firePostCreateHooks($table, $path)