Completed
Pull Request — master (#25)
by
unknown
02:43
created

BasePageTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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