BaseSettingTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 8
Bugs 1 Features 3
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 77
rs 10
c 8
b 1
f 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A getPackageProviders() 0 7 1
B getEnvironmentSetUp() 0 26 1
A getPackageAliases() 0 4 1
A resetDatabase() 0 20 1
1
<?php namespace Modules\Setting\Tests;
2
3
use Illuminate\Contracts\Console\Kernel;
4
use Illuminate\Database\Eloquent\Model;
5
use Maatwebsite\Sidebar\SidebarServiceProvider;
6
use Modules\Setting\Providers\SettingServiceProvider;
7
use Modules\Setting\Repositories\SettingRepository;
8
use Orchestra\Testbench\TestCase;
9
10
abstract class BaseSettingTest extends TestCase
11
{
12
    /**
13
     * @var SettingRepository
14
     */
15
    protected $settingRepository;
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
21
        $this->resetDatabase();
22
23
        $this->settingRepository = app(SettingRepository::class);
24
    }
25
26
    protected function getPackageProviders($app)
27
    {
28
        return [
29
            SettingServiceProvider::class,
30
            SidebarServiceProvider::class,
31
        ];
32
    }
33
34
    protected function getEnvironmentSetUp($app)
35
    {
36
        $app['path.base'] = __DIR__ . '/..';
37
        $app['config']->set('database.default', 'sqlite');
38
        $app['config']->set('database.connections.sqlite', array(
39
            'driver' => 'sqlite',
40
            'database' => ':memory:',
41
            'prefix' => '',
42
        ));
43
        $app['config']->set('asgard.core.settings', [
44
            'site-name' => [
45
                'description' => 'core::settings.site-name',
46
                'view' => 'text',
47
                'translatable' => true,
48
            ],
49
            'template' => [
50
                'description' => 'core::settings.template',
51
                'view' => 'core::fields.select-theme',
52
            ],
53
            'locales' => [
54
                'description' => 'core::settings.locales',
55
                'view' => 'core::fields.select-locales',
56
                'translatable' => false,
57
            ],
58
        ]);
59
    }
60
61
    protected function getPackageAliases($app)
62
    {
63
        return ['Eloquent' => Model::class];
64
    }
65
66
    private function resetDatabase()
67
    {
68
        // Relative to the testbench app folder: vendors/orchestra/testbench/src/fixture
69
        $migrationsPath = 'Database/Migrations';
70
        $artisan = $this->app->make(Kernel::class);
71
        // Makes sure the migrations table is created
72
        $artisan->call('migrate', [
73
            '--database' => 'sqlite',
74
            '--path'     => $migrationsPath,
75
        ]);
76
        // We empty all tables
77
        $artisan->call('migrate:reset', [
78
            '--database' => 'sqlite',
79
        ]);
80
        // Migrate
81
        $artisan->call('migrate', [
82
            '--database' => 'sqlite',
83
            '--path'     => $migrationsPath,
84
        ]);
85
    }
86
}
87