Passed
Push — master ( 8b76af...5f66ea )
by Marcin
03:35
created

QuickDatabaseMigrations::useDefaultWay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
It seems like artisan() 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 ignore-call  annotation

30
        $this->/** @scrutinizer ignore-call */ 
31
               artisan('migrate:fresh', [
Loading history...
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
Bug introduced by
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 ignore-call  annotation

38
        $this->/** @scrutinizer ignore-call */ 
39
               beforeApplicationDestroyed(function () {
Loading history...
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