-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'migrator-events' of https://github.com/wouter2203/frame…
…work into wouter2203-migrator-events
- Loading branch information
Showing
4 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Events; | ||
|
||
class NoMigrations | ||
{ | ||
/** | ||
* The migration method that was called. | ||
* | ||
* @var string | ||
*/ | ||
public $method; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param string $method | ||
* @return void | ||
*/ | ||
public function __construct($method) | ||
{ | ||
$this->method = $method; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database; | ||
|
||
use Illuminate\Database\Events\MigrationEnded; | ||
use Illuminate\Database\Events\MigrationsEnded; | ||
use Illuminate\Database\Events\MigrationsStarted; | ||
use Illuminate\Database\Events\MigrationStarted; | ||
use Illuminate\Database\Events\NoMigrations; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\Event; | ||
|
||
class MigratorEventsTest extends DatabaseTestCase | ||
{ | ||
protected function migrateOptions() | ||
{ | ||
return [ | ||
'--path' => realpath(__DIR__.'/stubs/'), | ||
'--realpath' => true, | ||
]; | ||
} | ||
|
||
public function testMigrationEventsAreFired() | ||
{ | ||
Event::fake(); | ||
|
||
$this->artisan('migrate', $this->migrateOptions()); | ||
$this->artisan('migrate:rollback', $this->migrateOptions()); | ||
|
||
Event::assertDispatched(MigrationsStarted::class, 2); | ||
Event::assertDispatched(MigrationsEnded::class, 2); | ||
Event::assertDispatched(MigrationStarted::class, 2); | ||
Event::assertDispatched(MigrationEnded::class, 2); | ||
} | ||
|
||
public function testMigrationEventsContainTheMigrationAndMethod() | ||
{ | ||
Event::fake(); | ||
|
||
$this->artisan('migrate', $this->migrateOptions()); | ||
$this->artisan('migrate:rollback', $this->migrateOptions()); | ||
|
||
Event::assertDispatched(MigrationStarted::class, function ($event) { | ||
return $event->method == 'up' && $event->migration instanceof Migration; | ||
}); | ||
Event::assertDispatched(MigrationStarted::class, function ($event) { | ||
return $event->method == 'down' && $event->migration instanceof Migration; | ||
}); | ||
Event::assertDispatched(MigrationEnded::class, function ($event) { | ||
return $event->method == 'up' && $event->migration instanceof Migration; | ||
}); | ||
Event::assertDispatched(MigrationEnded::class, function ($event) { | ||
return $event->method == 'down' && $event->migration instanceof Migration; | ||
}); | ||
} | ||
|
||
public function testTheNoMigrationEventIsFiredWhenNothingToMigrate() | ||
{ | ||
Event::fake(); | ||
|
||
$this->artisan('migrate'); | ||
$this->artisan('migrate:rollback'); | ||
|
||
Event::assertDispatched(NoMigrations::class, function ($event) { | ||
return $event->method == 'up'; | ||
}); | ||
Event::assertDispatched(NoMigrations::class, function ($event) { | ||
return $event->method == 'down'; | ||
}); | ||
} | ||
} |