| Total Complexity | 3 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | trait QuickDatabaseMigrations |
||
| 10 | { |
||
| 11 | use DatabaseMigrations { |
||
| 12 | runDatabaseMigrations as runDefaultDatabaseMigrations; |
||
| 13 | } |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Define hooks to migrate the database before and after each test. |
||
| 17 | * |
||
| 18 | * @return void |
||
| 19 | */ |
||
| 20 | public function runDatabaseMigrations() |
||
| 21 | { |
||
| 22 | // if disabled we just run parent method and that's it |
||
| 23 | if (! config('quick_migrations.enabled')) { |
||
| 24 | $this->useDefaultWay(); |
||
| 25 | |||
| 26 | return; |
||
| 27 | } |
||
| 28 | |||
| 29 | // otherwise we just run single migration that loads database dump |
||
| 30 | $this->artisan('migrate:fresh', [ |
||
|
|
|||
| 31 | '--path' => realpath(__DIR__ . '/../migrations'), |
||
| 32 | '--realpath' => 1, |
||
| 33 | ]); |
||
| 34 | |||
| 35 | $this->app[Kernel::class]->setArtisan(null); |
||
| 36 | |||
| 37 | // here we don't care about rollback (to make it faster) |
||
| 38 | $this->beforeApplicationDestroyed(function () { |
||
| 39 | RefreshDatabaseState::$migrated = false; |
||
| 40 | }); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Use default handling way (same as DatabaseMigrations). |
||
| 45 | * @codeCoverageIgnore |
||
| 46 | */ |
||
| 47 | protected function useDefaultWay() |
||
| 50 | } |
||
| 51 | } |
||
| 52 |