Skip to content

Commit 7cd4bdd

Browse files
committed
Updated testcase
1 parent cf10336 commit 7cd4bdd

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

tests/TestCase.php

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
44

5+
use App\Nova\Resource;
56
use Laravel\Nova\Nova;
67
use Illuminate\Foundation\Application;
78
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Database\Eloquent\Model;
810
use Illuminate\Database\Schema\Blueprint;
911
use Orchestra\Testbench\TestCase as Orchestra;
12+
use KirschbaumDevelopment\NovaInlineRelationship\NovaInlineRelationship;
1013
use KirschbaumDevelopment\NovaInlineRelationship\NovaInlineRelationshipServiceProvider;
1114
use KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource\Employee as EmployeeResource;
1215

@@ -34,6 +37,17 @@ public function setUp(): void
3437
$this->createTestModelsAndResources();
3538
}
3639

40+
/**
41+
* Set resource for a model in Nova
42+
*
43+
* @param string $model
44+
* @param string $resource
45+
*/
46+
public function setResourceForModel(string $model, string $resource)
47+
{
48+
Nova::$resourcesByModel[$model] = $resource;
49+
}
50+
3751
/**
3852
* Set up the environment.
3953
*
@@ -61,16 +75,40 @@ protected function setUpDatabase(): void
6175
$this->createTables();
6276
}
6377

78+
/**
79+
* Remove existing tables
80+
*/
6481
protected function cleanupDatabase()
6582
{
83+
Schema::dropIfExists('departments');
84+
Schema::dropIfExists('users');
6685
Schema::dropIfExists('employees');
6786
Schema::dropIfExists('profiles');
87+
Schema::dropIfExists('bills');
88+
Schema::dropIfExists('summaries');
89+
Schema::dropIfExists('comments');
6890
Schema::dropIfExists('teams');
6991
Schema::dropIfExists('employee_team');
7092
}
7193

94+
/**
95+
* Generate tables required for tests
96+
*/
7297
protected function createTables()
7398
{
99+
$this->app['db']->connection()->getSchemaBuilder()->create('departments', function (Blueprint $table) {
100+
$table->increments('id');
101+
$table->string('title');
102+
$table->timestamps();
103+
});
104+
105+
$this->app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) {
106+
$table->increments('id');
107+
$table->integer('department_id');
108+
$table->string('name');
109+
$table->timestamps();
110+
});
111+
74112
$this->app['db']->connection()->getSchemaBuilder()->create('employees', function (Blueprint $table) {
75113
$table->increments('id');
76114
$table->string('name');
@@ -84,6 +122,27 @@ protected function createTables()
84122
$table->timestamps();
85123
});
86124

125+
$this->app['db']->connection()->getSchemaBuilder()->create('bills', function (Blueprint $table) {
126+
$table->increments('id');
127+
$table->decimal('amount', 5, 2);
128+
$table->integer('employee_id');
129+
$table->timestamps();
130+
});
131+
132+
$this->app['db']->connection()->getSchemaBuilder()->create('summaries', function (Blueprint $table) {
133+
$table->increments('id');
134+
$table->string('text');
135+
$table->morphs('summarizable');
136+
$table->timestamps();
137+
});
138+
139+
$this->app['db']->connection()->getSchemaBuilder()->create('comments', function (Blueprint $table) {
140+
$table->increments('id');
141+
$table->string('text');
142+
$table->morphs('commentable');
143+
$table->timestamps();
144+
});
145+
87146
$this->app['db']->connection()->getSchemaBuilder()->create('teams', function (Blueprint $table) {
88147
$table->increments('id');
89148
$table->string('title');
@@ -93,6 +152,7 @@ protected function createTables()
93152
$this->app['db']->connection()->getSchemaBuilder()->create('employee_team', function (Blueprint $table) {
94153
$table->increments('employee_id');
95154
$table->string('team_id');
155+
$table->timestamps();
96156
});
97157
}
98158

@@ -101,7 +161,7 @@ protected function createTables()
101161
*/
102162
protected function createTestModelsAndResources(): void
103163
{
104-
Nova::$resourcesByModel[Employee::class] = EmployeeResource::class;
164+
$this->setResourceForModel(Employee::class, EmployeeResource::class);
105165

106166
$this->employeeModel = Employee::create(['name' => 'test']);
107167
$this->employeeResource = new EmployeeResource($this->employeeModel);
@@ -118,4 +178,13 @@ protected function getPackageProviders($app)
118178
{
119179
return [NovaInlineRelationshipServiceProvider::class];
120180
}
181+
182+
/**
183+
* {@inheritdoc}
184+
*/
185+
protected function tearDown(): void
186+
{
187+
parent::tearDown();
188+
NovaInlineRelationship::$observedModels = [];
189+
}
121190
}

0 commit comments

Comments
 (0)