Skip to content

[9.x] Add path to post create hooks in MigrationCreator #35213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Illuminate/Database/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 9 additions & 5 deletions tests/Database/DatabaseMigrationCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()
Expand Down