Completed
Pull Request — master (#94)
by
unknown
02:21 queued 01:02
created

TestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 67
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A getPackageProviders() 0 6 1
A getEnvironmentSetUp() 0 9 1
A setUpDatabase() 0 16 1
A setUpSoftDeletes() 0 6 1
A setUpCustomSortColumns() 0 8 1
1
<?php
2
3
namespace Spatie\EloquentSortable\Test;
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Orchestra\Testbench\TestCase as Orchestra;
7
use Spatie\EloquentSortable\EloquentSortableServiceProvider;
8
9
abstract class TestCase extends Orchestra
10
{
11
    public function setUp(): void
12
    {
13
        parent::setUp();
14
15
        $this->setUpDatabase();
16
    }
17
18
    /**
19
     * @param \Illuminate\Foundation\Application $app
20
     *
21
     * @return array
22
     */
23
    protected function getPackageProviders($app)
24
    {
25
        return [
26
            EloquentSortableServiceProvider::class,
27
        ];
28
    }
29
30
    /**
31
     * @param \Illuminate\Foundation\Application $app
32
     */
33
    protected function getEnvironmentSetUp($app)
34
    {
35
        $app['config']->set('database.default', 'sqlite');
36
        $app['config']->set('database.connections.sqlite', [
37
            'driver' => 'sqlite',
38
            'database' => ':memory:',
39
            'prefix' => '',
40
        ]);
41
    }
42
43
    protected function setUpDatabase()
44
    {
45
        $this->app['db']->connection()->getSchemaBuilder()->create('dummies', function (Blueprint $table) {
46
            $table->increments('id');
47
            $table->string('name');
48
            $table->string('custom_column_sort');
49
            $table->integer('order_column');
50
        });
51
52
        collect(range(1, 20))->each(function (int $i) {
53
            Dummy::create([
54
                'name' => $i,
55
                'custom_column_sort' => rand(),
56
            ]);
57
        });
58
    }
59
60
    protected function setUpSoftDeletes()
61
    {
62
        $this->app['db']->connection()->getSchemaBuilder()->table('dummies', function (Blueprint $table) {
63
            $table->softDeletes();
64
        });
65
    }
66
67
    protected function setUpCustomSortColumns()
68
    {
69
        $this->app['db']->connection()->getSchemaBuilder()->create('dummy_customs', function (Blueprint $table) {
70
            $table->increments('id');
71
            $table->string('name');
72
            $table->integer('custom_order_column_name');
73
        });
74
    }
75
}
76