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
|
|
|
|