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