11namespace App\Tests;
22
3+ @if ($hasModificationEndpoints )
4+ use RonasIT\Support\Tests\ModelTestState;
5+ use {{ $modelsNamespace } } \{{ $entity } } ;
6+ @endif
37@if ($withAuth )
48use {{ $modelsNamespace } } \User;
59@endif
@@ -12,13 +16,21 @@ class {{$entity}}Test extends TestCase
1216@if ($withAuth )
1317 protected static User $user;
1418
19+ @endif
20+ @if ($hasModificationEndpoints )
21+ protected static ModelTestState ${{ \Illuminate \Support \Str:: camel ($entity ) } } State;
22+
1523@endif
1624 public function setUp() : void
1725 {
1826 parent::setUp();
1927@if ($withAuth )
2028
2129 self::$user ??= User::find(1);
30+ @endif
31+ @if ($hasModificationEndpoints )
32+
33+ self::${{ \Illuminate \Support \Str:: camel ($entity ) } } State ??= new ModelTestState({{ $entity } } ::class);
2234@endif
2335 }
2436
@@ -37,7 +49,8 @@ public function testCreate()
3749
3850 $this->assertEqualsFixture('create_{{ \Illuminate \Support \Str:: snake ($entity ) } } _response.json', $response->json());
3951
40- $this->assertDatabaseHas('{{ $databaseTableName } } ', $this->getJsonFixture('create_{{ \Illuminate \Support \Str:: snake ($entity ) } } _response.json'));
52+ // TODO: Need to remove last argument after first successful start
53+ self::${{ \Illuminate \Support \Str:: camel ($entity ) } } State->assertChangesEqualsFixture('create_{{ \Illuminate \Support \Str:: snake ($entity ) } } _state.json', true);
4154 }
4255
4356@if ($withAuth )
@@ -65,7 +78,8 @@ public function testUpdate()
6578
6679 $response->assertNoContent();
6780
68- $this->assertDatabaseHas('{{ $databaseTableName } } ', $data);
81+ // TODO: Need to remove last argument after first successful start
82+ self::${{ \Illuminate \Support \Str:: camel ($entity ) } } State->assertChangesEqualsFixture('update_{{ \Illuminate \Support \Str:: snake ($entity ) } } _state.json', true);
6983 }
7084
7185 public function testUpdateNotExists()
@@ -104,9 +118,8 @@ public function testDelete()
104118
105119 $response->assertNoContent();
106120
107- $this->assertDatabaseMissing('{{ $databaseTableName } } ', [
108- 'id' => 1
109- ]);
121+ // TODO: Need to remove last argument after first successful start
122+ self::${{ \Illuminate \Support \Str:: camel ($entity ) } } State->assertChangesEqualsFixture('delete_{{ \Illuminate \Support \Str:: snake ($entity ) } } _state.json', true);
110123 }
111124
112125 public function testDeleteNotExists()
@@ -119,9 +132,7 @@ public function testDeleteNotExists()
119132
120133 $response->assertNotFound();
121134
122- $this->assertDatabaseMissing('{{ $databaseTableName } } ', [
123- 'id' => 0
124- ]);
135+ self::${{ \Illuminate \Support \Str:: camel ($entity ) } } State->assertNotChanged();
125136 }
126137
127138@if ($withAuth )
0 commit comments