Completed
Push — master ( a0b016...728b96 )
by Stéphane
24:07
created

TestCase::getEnvironmentSetUp()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 1
dl 0
loc 50
rs 9.0909
c 0
b 0
f 0
1
<?php namespace Tests;
2
3
/**
4
 * Simplifies the creation of tests creating a full application, running migrations and loading multiple Service Providers
5
 */
6
7
/**
8
 * Class TestCase
9
 * @codeCoverageIgnore
10
 */
11
class TestCase extends \Orchestra\Testbench\TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
12
{
13
    /**
14
     * Setup the test environment.
15
     *
16
     * @return void
17
     */
18
    public function setUp(): void
19
    {
20
        if (!$this->app) {
21
            $this->refreshApplication();
22
        }
23
24
        $artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
25
        $artisan->call('vendor:publish');
26
27
        //refresh configuration values
28
        $this->refreshApplication();
29
    }
30
31
    /**
32
     * Clean up the testing environment before the next test.
33
     *
34
     * @return void
35
     */
36
    public function tearDown(): void
37
    {
38
        parent::tearDown();
39
    }
40
41
    /**
42
     * Define environment setup.
43
     *
44
     * @param \Illuminate\Foundation\Application $app
45
     * @return void
46
     */
47
    protected function getEnvironmentSetUp($app)
48
    {
49
        // reset base path to point to our package's src directory
50
        $app['path.base'] = realpath(__DIR__ . '/..');
51
52
        $app['config']->set(
53
            'database.connections',
54
            [
55
                'default' => [
56
                    'driver' => 'sqlite',
57
                    'database' => ':memory:',
58
                    'prefix' => '',
59
                ],
60
                // create database travis_test;
61
                // grant usage on *.* to travis@localhost;
62
                // grant all privileges on travis_test.* to travis@localhost;
63
                'travis-mysql' => [
64
                    'driver'    => 'mysql',
65
                    'host'      => 'localhost',
66
                    'database'  => 'travis_test',
67
                    'username'  => 'travis',
68
                    'password'  => '',
69
                    'charset'   => 'utf8',
70
                    'collation' => 'utf8_unicode_ci',
71
                    'prefix'    => '',
72
                ],
73
                'travis-pgsql' => [
74
                    'driver'   => 'pgsql',
75
                    'host'     => 'localhost',
76
                    'database' => 'travis_test',
77
                    'username' => 'postgres',
78
                    'password' => '',
79
                    'charset'  => 'utf8',
80
                    'prefix'   => '',
81
                    'schema'   => 'public',
82
                ],
83
            ]
84
        );
85
86
        $app['config']->set('database.default', 'default');
87
        if ($db = getenv('DB')) {
88
            if ($db == 'pgsql') {
89
                $app['config']->set('database.default', 'travis-pgsql');
90
            }
91
92
            if ($db == 'mysql') {
93
                $app['config']->set('database.default', 'travis-mysql');
94
            }
95
        }
96
    }
97
}
98