This repository was archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProvisionedTestCase.php
137 lines (118 loc) · 3.46 KB
/
ProvisionedTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace Czim\DataStore\Test;
use Czim\DataStore\Providers\DataStoreServiceProvider;
use Czim\DataStore\Test\Helpers\Models\TestModel;
use Czim\DataStore\Test\Helpers\Models\TestMorphRelatedModel;
use Czim\DataStore\Test\Helpers\Models\TestRelatedModel;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
abstract class ProvisionedTestCase extends TestCase
{
/**
* {@inheritdoc}
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('paperclip', include(realpath(dirname(__DIR__) . '/config/datastore.php')));
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', $this->getDatabaseConfigForSqlite());
}
/**
* {@inheritdoc}
*/
public function getPackageProviders($app)
{
return [
DataStoreServiceProvider::class,
];
}
/**
* Setup the test environment.
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->setUpDatabase();
}
/**
* Returns the testing config for a (shared) SQLite connection.
*
* @return array
*/
protected function getDatabaseConfigForSqlite()
{
return [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
];
}
/**
* Sets up the database for testing.
*/
protected function setUpDatabase()
{
Schema::create('test_models', function($table) {
/** @var Blueprint $table */
$table->increments('id');
$table->string('name', 255)->nullable();
$table->nullableTimestamps();
});
}
/**
* Sets up the database for relational testing.
*/
protected function setUpRelatedDatabase()
{
Schema::create('test_related_models', function($table) {
/** @var Blueprint $table */
$table->increments('id');
$table->string('name', 255)->nullable();
$table->integer('test_model_id')->unsigned()->nullable();
$table->nullableTimestamps();
});
Schema::create('test_morph_related_models', function($table) {
/** @var Blueprint $table */
$table->increments('id');
$table->string('name', 255)->nullable();
$table->integer('morphable_id')->unsigned()->nullable();
$table->string('morphable_type', 255)->nullable();
$table->nullableTimestamps();
});
}
/**
* @return TestModel
*/
protected function createTestModel()
{
return TestModel::create([
'name' => 'testing default name',
]);
}
/**
* @return TestModel
*/
protected function createRelatedTestModel()
{
/** @var TestModel $model */
$model = TestModel::create([
'name' => 'testing default name',
]);
TestRelatedModel::create([
'name' => 'Related One',
'test_model_id' => $model->id,
]);
TestRelatedModel::create([
'name' => 'Related Two',
'test_model_id' => $model->id,
]);
/** @var TestMorphRelatedModel $morph */
$morph = new TestMorphRelatedModel([
'name' => 'Morph One',
]);
$model->testMorphRelatedModels()->save($morph);
return $model;
}
}