output = Mockery::mock(OutputInterface::class); $this->subject = $this->app->make('migrator'); $this->subject->setOutput($this->output); $this->subject->getRepository()->createRepository(); } public function testMigrate() { $this->expectOutput('Migrating: 2014_10_12_000000_create_people_table'); $this->expectOutput(Mockery::pattern('#Migrated: 2014_10_12_000000_create_people_table (.*)#')); $this->expectOutput('Migrating: 2015_10_04_000000_modify_people_table'); $this->expectOutput(Mockery::pattern('#Migrated: 2015_10_04_000000_modify_people_table (.*)#')); $this->expectOutput('Migrating: 2016_10_04_000000_modify_people_table'); $this->expectOutput(Mockery::pattern('#Migrated: 2016_10_04_000000_modify_people_table (.*)#')); $this->subject->run([__DIR__.'/fixtures']); self::assertTrue(DB::getSchemaBuilder()->hasTable('people')); self::assertTrue(DB::getSchemaBuilder()->hasColumn('people', 'first_name')); self::assertTrue(DB::getSchemaBuilder()->hasColumn('people', 'last_name')); } public function testRollback() { $this->getConnection()->statement('CREATE TABLE people(id INT, first_name VARCHAR, last_name VARCHAR);'); $this->subject->getRepository()->log('2014_10_12_000000_create_people_table', 1); $this->subject->getRepository()->log('2015_10_04_000000_modify_people_table', 1); $this->subject->getRepository()->log('2016_10_04_000000_modify_people_table', 1); $this->expectOutput('Rolling back: 2016_10_04_000000_modify_people_table'); $this->expectOutput(Mockery::pattern('#Rolled back: 2016_10_04_000000_modify_people_table (.*)#')); $this->expectOutput('Rolling back: 2015_10_04_000000_modify_people_table'); $this->expectOutput(Mockery::pattern('#Rolled back: 2015_10_04_000000_modify_people_table (.*)#')); $this->expectOutput('Rolling back: 2014_10_12_000000_create_people_table'); $this->expectOutput(Mockery::pattern('#Rolled back: 2014_10_12_000000_create_people_table (.*)#')); $this->subject->rollback([__DIR__.'/fixtures']); self::assertFalse(DB::getSchemaBuilder()->hasTable('people')); } public function testPretendMigrate() { $this->expectOutput('CreatePeopleTable: 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('CreatePeopleTable: create unique index "people_email_unique" on "people" ("email")'); $this->expectOutput('ModifyPeopleTable: alter table "people" add column "first_name" varchar'); $this->expectOutput('2016_10_04_000000_modify_people_table: alter table "people" add column "last_name" varchar'); $this->subject->run([__DIR__.'/fixtures'], ['pretend' => true]); self::assertFalse(DB::getSchemaBuilder()->hasTable('people')); } private function expectOutput($argument): void { $this->output->shouldReceive('writeln')->once()->with($argument); } }