getCreator(); $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo'); $creator->getFilesystem()->shouldReceive('exists')->once()->with('stubs/migration.stub')->andReturn(false); $creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/migration.stub')->andReturn('DummyClass'); $creator->getFilesystem()->shouldReceive('ensureDirectoryExists')->once()->with('foo'); $creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar'); $creator->getFilesystem()->shouldReceive('glob')->once()->with('foo/*.php')->andReturn(['foo/foo_create_bar.php']); $creator->getFilesystem()->shouldReceive('requireOnce')->once()->with('foo/foo_create_bar.php'); $creator->create('create_bar', 'foo'); } public function testBasicCreateMethodCallsPostCreateHooks() { $table = 'baz'; $creator = $this->getCreator(); unset($_SERVER['__migration.creator']); $creator->afterCreate(function ($table) { $_SERVER['__migration.creator'] = $table; }); $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo'); $creator->getFilesystem()->shouldReceive('exists')->once()->with('stubs/migration.update.stub')->andReturn(false); $creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/migration.update.stub')->andReturn('DummyClass DummyTable'); $creator->getFilesystem()->shouldReceive('ensureDirectoryExists')->once()->with('foo'); $creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz'); $creator->getFilesystem()->shouldReceive('glob')->once()->with('foo/*.php')->andReturn(['foo/foo_create_bar.php']); $creator->getFilesystem()->shouldReceive('requireOnce')->once()->with('foo/foo_create_bar.php'); $creator->create('create_bar', 'foo', $table); $this->assertEquals($_SERVER['__migration.creator'], $table); unset($_SERVER['__migration.creator']); } public function testTableUpdateMigrationStoresMigrationFile() { $creator = $this->getCreator(); $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo'); $creator->getFilesystem()->shouldReceive('exists')->once()->with('stubs/migration.update.stub')->andReturn(false); $creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/migration.update.stub')->andReturn('DummyClass DummyTable'); $creator->getFilesystem()->shouldReceive('ensureDirectoryExists')->once()->with('foo'); $creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz'); $creator->getFilesystem()->shouldReceive('glob')->once()->with('foo/*.php')->andReturn(['foo/foo_create_bar.php']); $creator->getFilesystem()->shouldReceive('requireOnce')->once()->with('foo/foo_create_bar.php'); $creator->create('create_bar', 'foo', 'baz'); } public function testTableCreationMigrationStoresMigrationFile() { $creator = $this->getCreator(); $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo'); $creator->getFilesystem()->shouldReceive('exists')->once()->with('stubs/migration.create.stub')->andReturn(false); $creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/migration.create.stub')->andReturn('DummyClass DummyTable'); $creator->getFilesystem()->shouldReceive('ensureDirectoryExists')->once()->with('foo'); $creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz'); $creator->getFilesystem()->shouldReceive('glob')->once()->with('foo/*.php')->andReturn(['foo/foo_create_bar.php']); $creator->getFilesystem()->shouldReceive('requireOnce')->once()->with('foo/foo_create_bar.php'); $creator->create('create_bar', 'foo', 'baz', true); } public function testTableUpdateMigrationWontCreateDuplicateClass() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A MigrationCreatorFakeMigration class already exists.'); $creator = $this->getCreator(); $creator->getFilesystem()->shouldReceive('glob')->once()->with('foo/*.php')->andReturn(['foo/foo_create_bar.php']); $creator->getFilesystem()->shouldReceive('requireOnce')->once()->with('foo/foo_create_bar.php'); $creator->create('migration_creator_fake_migration', 'foo'); } protected function getCreator() { $files = m::mock(Filesystem::class); $customStubs = 'stubs'; return $this->getMockBuilder(MigrationCreator::class) ->onlyMethods(['getDatePrefix']) ->setConstructorArgs([$files, $customStubs]) ->getMock(); } }