1 | <?php |
||||||
2 | |||||||
3 | namespace Mnabialek\LaravelQuickMigrations; |
||||||
4 | |||||||
5 | use Illuminate\Contracts\Console\Kernel; |
||||||
6 | use Illuminate\Foundation\Testing\DatabaseMigrations; |
||||||
7 | use Illuminate\Foundation\Testing\RefreshDatabaseState; |
||||||
8 | |||||||
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', [ |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
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 () { |
||||||
0 ignored issues
–
show
It seems like
beforeApplicationDestroyed() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
39 | RefreshDatabaseState::$migrated = false; |
||||||
40 | }); |
||||||
41 | } |
||||||
42 | |||||||
43 | /** |
||||||
44 | * Use default handling way (same as DatabaseMigrations). |
||||||
45 | * @codeCoverageIgnore |
||||||
46 | */ |
||||||
47 | protected function useDefaultWay() |
||||||
48 | { |
||||||
49 | $this->runDefaultDatabaseMigrations(); |
||||||
50 | } |
||||||
51 | } |
||||||
52 |