Completed
Push — master ( 1ed12b...1ef741 )
by Nicolas
07:28
created

BaseTestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Modules\Tag\Tests;
4
5
use Illuminate\Contracts\Console\Kernel;
6
use Illuminate\View\ViewServiceProvider;
7
use Modules\Core\Providers\CoreServiceProvider;
8
use Modules\Page\Providers\PageServiceProvider;
9
use Modules\Tag\Providers\TagServiceProvider;
10
use Nwidart\Modules\LaravelModulesServiceProvider;
11
use Orchestra\Testbench\TestCase;
12
13
abstract class BaseTestCase extends TestCase
14
{
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        $this->resetDatabase();
20
    }
21
22
    protected function getPackageProviders($app)
23
    {
24
        return [
25
            ViewServiceProvider::class,
26
            LaravelModulesServiceProvider::class,
27
            CoreServiceProvider::class,
28
            PageServiceProvider::class,
29
            TagServiceProvider::class,
30
        ];
31
    }
32
33
    protected function getEnvironmentSetUp($app)
34
    {
35
        $app['path.base'] = __DIR__ . '/..';
36
        $app['config']->set('database.default', 'sqlite');
37
        $app['config']->set('database.connections.sqlite', array(
38
            'driver' => 'sqlite',
39
            'database' => ':memory:',
40
            'prefix' => '',
41
        ));
42
        $app['config']->set('translatable.locales', ['en', 'fr']);
43
        $app['config']->set('modules.paths.modules', __DIR__ . '/../Modules');
44
    }
45
46
    private function resetDatabase()
47
    {
48
        // Relative to the testbench app folder: vendors/orchestra/testbench/src/fixture
49
        $migrationsPath = 'Database/Migrations';
50
        $artisan = $this->app->make(Kernel::class);
51
        // Makes sure the migrations table is created
52
        $artisan->call('migrate', [
53
            '--database' => 'sqlite',
54
            '--path'     => $migrationsPath,
55
        ]);
56
        // We empty all tables
57
        $artisan->call('migrate:reset', [
58
            '--database' => 'sqlite',
59
        ]);
60
        // Migrate
61
        $artisan->call('migrate', [
62
            '--database' => 'sqlite',
63
            '--path'     => $migrationsPath,
64
        ]);
65
        $artisan->call('migrate', [
66
            '--database' => 'sqlite',
67
            '--path'     => 'Modules/Page/Database/Migrations',
68
        ]);
69
    }
70
}
71