Skip to content

Commit

Permalink
Guess the --create option when generation migrations with the common …
Browse files Browse the repository at this point in the history
…create_[TABLE_NAME]_table pattern
  • Loading branch information
sileence committed Jul 13, 2017
1 parent ac9f29d commit e96e5ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function handle()
$create = true;
}

if (! $table) {
if (preg_match('/^create_(\w+)_table$/', $name, $matches)) {
$table = $matches[1];

$create = true;
}
}

// Now we are ready to write the migration out to disk. Once we've written
// the migration out, we will dump-autoload for the entire framework to
// make sure that the migrations are registered by the class loaders.
Expand Down
15 changes: 15 additions & 0 deletions tests/Database/DatabaseMigrationMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenTableIsSet()
$this->runCommand($command, ['name' => 'create_foo', '--create' => 'users']);
}

public function testBasicCreateGivesCreatorProperArgumentsWhenCreateTablePatternIsFound()
{
$command = new MigrateMakeCommand(
$creator = m::mock('Illuminate\Database\Migrations\MigrationCreator'),
m::mock('Illuminate\Support\Composer')->shouldIgnoreMissing(),
__DIR__.'/vendor'
);
$app = new \Illuminate\Foundation\Application;
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$creator->shouldReceive('create')->once()->with('create_users_table', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true);

$this->runCommand($command, ['name' => 'create_users_table']);
}

public function testCanSpecifyPathToCreateMigrationsIn()
{
$command = new MigrateMakeCommand(
Expand Down

0 comments on commit e96e5ab

Please sign in to comment.