TestCase::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MathieuTu\JsonSyncer\Tests;
4
5
use Illuminate\Database\Eloquent\Model;
6
use MathieuTu\JsonSyncer\Tests\Stubs\Bar;
7
use MathieuTu\JsonSyncer\Tests\Stubs\Baz;
8
use MathieuTu\JsonSyncer\Tests\Stubs\DoNotExport;
9
use MathieuTu\JsonSyncer\Tests\Stubs\Foo;
10
11
class TestCase extends \Orchestra\Testbench\TestCase
12
{
13
    public function setUp(): void
14
    {
15
        parent::setUp();
16
17
        $this->createTable(new Foo());
18
        $this->createTable(new Bar());
19
        $this->createTable(new Baz());
20
        $this->createTable(new DoNotExport());
21
    }
22
23
    protected function getEnvironmentSetUp($app)
24
    {
25
        // Setup default database to use sqlite :memory:
26
        $app['config']->set('database.default', 'memory');
27
        $app['config']->set('database.connections.memory', [
28
            'driver' => 'sqlite',
29
            'database' => ':memory:',
30
            'prefix' => '',
31
        ]);
32
    }
33
34
    protected function createTable(Model $model)
35
    {
36
        $this->app['db']->connection()->getSchemaBuilder()->create(
37
            $model->getTable(),
38
            function (\Illuminate\Database\Schema\Blueprint $table) use ($model) {
39
                $table->increments('id');
40
                foreach ($model->getFillable() as $column) {
41
                    $table->string($column)->nullable();
42
                }
43
            }
44
        );
45
    }
46
}
47