Skip to content

Commit

Permalink
refactor: make static variable in generated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aizlee committed Nov 28, 2024
1 parent 3dd077c commit 704f473
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions stubs/test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
class {{$entity}}Test extends TestCase
{
@if ($withAuth)
protected $user;
protected static User $user;

@endif
public function setUp() : void
{
parent::setUp();
@if ($withAuth)

$this->user = User::find(1);
self::$user ??= User::find(1);
@endif
}

Expand All @@ -30,7 +30,7 @@ public function testCreate()
@if (!$withAuth)
$response = $this->json('post', '/{{$entities}}', $data);
@else
$response = $this->actingAs($this->user)->json('post', '/{{$entities}}', $data);
$response = $this->actingAs(self::$user)->json('post', '/{{$entities}}', $data);
@endif

$response->assertCreated();
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testUpdate()
@if (!$withAuth)
$response = $this->json('put', '/{{$entities}}/1', $data);
@else
$response = $this->actingAs($this->user)->json('put', '/{{$entities}}/1', $data);
$response = $this->actingAs(self::$user)->json('put', '/{{$entities}}/1', $data);
@endif

$response->assertNoContent();
Expand All @@ -75,7 +75,7 @@ public function testUpdateNotExists()
@if (!$withAuth)
$response = $this->json('put', '/{{$entities}}/0', $data);
@else
$response = $this->actingAs($this->user)->json('put', '/{{$entities}}/0', $data);
$response = $this->actingAs(self::$user)->json('put', '/{{$entities}}/0', $data);
@endif

$response->assertNotFound();
Expand All @@ -99,7 +99,7 @@ public function testDelete()
@if (!$withAuth)
$response = $this->json('delete', '/{{$entities}}/1');
@else
$response = $this->actingAs($this->user)->json('delete', '/{{$entities}}/1');
$response = $this->actingAs(self::$user)->json('delete', '/{{$entities}}/1');
@endif

$response->assertNoContent();
Expand All @@ -114,7 +114,7 @@ public function testDeleteNotExists()
@if (!$withAuth)
$response = $this->json('delete', '/{{$entities}}/0');
@else
$response = $this->actingAs($this->user)->json('delete', '/{{$entities}}/0');
$response = $this->actingAs(self::$user)->json('delete', '/{{$entities}}/0');
@endif

$response->assertNotFound();
Expand All @@ -140,7 +140,7 @@ public function testGet()
@if (!$withAuth)
$response = $this->json('get', '/{{$entities}}/1');
@else
$response = $this->actingAs($this->user)->json('get', '/{{$entities}}/1');
$response = $this->actingAs(self::$user)->json('get', '/{{$entities}}/1');
@endif

$response->assertOk();
Expand All @@ -156,7 +156,7 @@ public function testGetNotExists()
@if (!$withAuth)
$response = $this->json('get', '/{{$entities}}/0');
@else
$response = $this->actingAs($this->user)->json('get', '/{{$entities}}/0');
$response = $this->actingAs(self::$user)->json('get', '/{{$entities}}/0');
@endif

$response->assertNotFound();
Expand Down

0 comments on commit 704f473

Please sign in to comment.