1010class {{ $entity } } Test extends TestCase
1111{
1212@if ($withAuth )
13- protected $user;
13+ protected static User $user;
1414
1515@endif
1616 public function setUp() : void
1717 {
1818 parent::setUp();
1919@if ($withAuth )
2020
21- $this-> user = User::find(1);
21+ self::$ user ?? = User::find(1);
2222@endif
2323 }
2424
@@ -30,7 +30,7 @@ public function testCreate()
3030@if (! $withAuth )
3131 $response = $this->json('post', '/{{ $entities } } ', $data);
3232@else
33- $response = $this->actingAs($this-> user)->json('post', '/{{ $entities } } ', $data);
33+ $response = $this->actingAs(self::$ user)->json('post', '/{{ $entities } } ', $data);
3434@endif
3535
3636 $response->assertCreated();
@@ -60,7 +60,7 @@ public function testUpdate()
6060@if (! $withAuth )
6161 $response = $this->json('put', '/{{ $entities } } /1', $data);
6262@else
63- $response = $this->actingAs($this-> user)->json('put', '/{{ $entities } } /1', $data);
63+ $response = $this->actingAs(self::$ user)->json('put', '/{{ $entities } } /1', $data);
6464@endif
6565
6666 $response->assertNoContent();
@@ -75,7 +75,7 @@ public function testUpdateNotExists()
7575@if (! $withAuth )
7676 $response = $this->json('put', '/{{ $entities } } /0', $data);
7777@else
78- $response = $this->actingAs($this-> user)->json('put', '/{{ $entities } } /0', $data);
78+ $response = $this->actingAs(self::$ user)->json('put', '/{{ $entities } } /0', $data);
7979@endif
8080
8181 $response->assertNotFound();
@@ -99,7 +99,7 @@ public function testDelete()
9999@if (! $withAuth )
100100 $response = $this->json('delete', '/{{ $entities } } /1');
101101@else
102- $response = $this->actingAs($this-> user)->json('delete', '/{{ $entities } } /1');
102+ $response = $this->actingAs(self::$ user)->json('delete', '/{{ $entities } } /1');
103103@endif
104104
105105 $response->assertNoContent();
@@ -114,7 +114,7 @@ public function testDeleteNotExists()
114114@if (! $withAuth )
115115 $response = $this->json('delete', '/{{ $entities } } /0');
116116@else
117- $response = $this->actingAs($this-> user)->json('delete', '/{{ $entities } } /0');
117+ $response = $this->actingAs(self::$ user)->json('delete', '/{{ $entities } } /0');
118118@endif
119119
120120 $response->assertNotFound();
@@ -140,7 +140,7 @@ public function testGet()
140140@if (! $withAuth )
141141 $response = $this->json('get', '/{{ $entities } } /1');
142142@else
143- $response = $this->actingAs($this-> user)->json('get', '/{{ $entities } } /1');
143+ $response = $this->actingAs(self::$ user)->json('get', '/{{ $entities } } /1');
144144@endif
145145
146146 $response->assertOk();
@@ -156,7 +156,7 @@ public function testGetNotExists()
156156@if (! $withAuth )
157157 $response = $this->json('get', '/{{ $entities } } /0');
158158@else
159- $response = $this->actingAs($this-> user)->json('get', '/{{ $entities } } /0');
159+ $response = $this->actingAs(self::$ user)->json('get', '/{{ $entities } } /0');
160160@endif
161161
162162 $response->assertNotFound();
0 commit comments