Test Setup Failed
Push — master ( 698635...8c1479 )
by Jeremy
05:28 queued 12s
created

RefreshDatabase::refreshInMemoryDatabase()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 23
rs 9.4888
c 1
b 0
f 0
cc 5
nc 4
nop 0
1
<?php
2
3
namespace jeremykenedy\LaravelRoles\Test;
4
5
use Illuminate\Contracts\Console\Kernel;
6
use Illuminate\Foundation\Testing\RefreshDatabase as TestingRefreshDatabase;
7
8
trait RefreshDatabase
9
{
10
    use TestingRefreshDatabase;
11
12
    protected $seeder = [
13
        \jeremykenedy\LaravelRoles\Database\Seeders\DefaultPermissionsTableSeeder::class,
14
        \jeremykenedy\LaravelRoles\Database\Seeders\DefaultRolesTableSeeder::class,
15
        \jeremykenedy\LaravelRoles\Database\Seeders\DefaultConnectRelationshipsSeeder::class,
16
    ];
17
18
    /**
19
     * Refresh the in-memory database.
20
     *
21
     * @return void
22
     */
23
    protected function refreshInMemoryDatabase()
24
    {
25
        $this->artisan('migrate', $this->migrateUsing());
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

25
        $this->/** @scrutinizer ignore-call */ 
26
               artisan('migrate', $this->migrateUsing());
Loading history...
26
27
        if ($this->shouldSeed()) {
28
            $options = ['--force' => true];
29
30
            if ($seeders = $this->seeder()) {
31
                if (is_array($seeders)) {
0 ignored issues
show
introduced by
The condition is_array($seeders) is always true.
Loading history...
32
                    foreach ($seeders as $seeder) {
33
                        $options['--class'] = $seeder;
34
                        $this->artisan('db:seed', $options);
35
                    }
36
                } else {
37
                    $options['--class'] = $seeders;
38
                    $this->artisan('db:seed', $options);
39
                }
40
            } else {
41
                $this->artisan('db:seed', $options);
42
            }
43
        }
44
45
        $this->app[Kernel::class]->setArtisan(null);
46
    }
47
48
    /**
49
     * The parameters that should be used when running "migrate".
50
     *
51
     * @return array
52
     */
53
    protected function migrateUsing()
54
    {
55
        return [
56
            /**
57
             * Non standard path
58
             *
59
             * $this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations'
60
             * with `vendor/orchestra/testbench-core/laravel` as basePath
61
             *
62
             * @see \Illuminate\Database\Console\Migrations\BaseCommand
63
             */
64
            '--path' => realpath(__DIR__ . '/../src/Database/Migrations'),
65
            '--realpath' => true,
66
        ];
67
    }
68
}
69