Skip to content

Commit

Permalink
Display migration class name in pretendToRun
Browse files Browse the repository at this point in the history
Due to backward compatibility, classic migrations (non-anonymous) should
have their class name displayed while running migrations with --pretend,
instead of the migration name, like anywhere else in the code.
  • Loading branch information
thiagorb committed Apr 11, 2021
1 parent 9cdb5cc commit 64272b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Illuminate/Database/Migrations/Migrator.php
Expand Up @@ -410,7 +410,12 @@ protected function runMigration($migration, $method)
protected function pretendToRun($migration, $method)
{
foreach ($this->getQueries($migration, $method) as $query) {
$name = $this->getMigrationName((new ReflectionClass($migration))->getFileName());
$name = get_class($migration);

$reflectionClass = new ReflectionClass($migration);
if ($reflectionClass->isAnonymous()) {
$name = $this->getMigrationName($reflectionClass->getFileName());
}

$this->note("<info>{$name}:</info> {$query['query']}");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Migration/MigratorTest.php
Expand Up @@ -74,8 +74,8 @@ public function testRollback()

public function testPretendMigrate()
{
$this->expectOutput('<info>2014_10_12_000000_create_people_table:</info> create table "people" ("id" integer not null primary key autoincrement, "name" varchar not null, "email" varchar not null, "password" varchar not null, "remember_token" varchar, "created_at" datetime, "updated_at" datetime)');
$this->expectOutput('<info>2014_10_12_000000_create_people_table:</info> create unique index "people_email_unique" on "people" ("email")');
$this->expectOutput('<info>CreatePeopleTable:</info> create table "people" ("id" integer not null primary key autoincrement, "name" varchar not null, "email" varchar not null, "password" varchar not null, "remember_token" varchar, "created_at" datetime, "updated_at" datetime)');
$this->expectOutput('<info>CreatePeopleTable:</info> create unique index "people_email_unique" on "people" ("email")');
$this->expectOutput('<info>2015_10_04_000000_modify_people_table:</info> alter table "people" add column "first_name" varchar');
$this->expectOutput('<info>2016_10_04_000000_modify_people_table:</info> alter table "people" add column "last_name" varchar');

Expand Down

0 comments on commit 64272b4

Please sign in to comment.