Skip to content

Commit 208a337

Browse files
authored
Merge pull request #111 from RonasIT/feat/support-phpunit-11
feat: implemented supporting of PHPUnit v11
2 parents e270f60 + 704f473 commit 208a337

File tree

3 files changed

+67
-206
lines changed

3 files changed

+67
-206
lines changed

stubs/nova_test.blade.php

Lines changed: 24 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
@php($shouldUseStatus = version_compare(app()->version(), '7', '<'))
21
namespace App\Tests;
32

43
use App\Models\{{$entity}};
4+
use PHPUnit\Framework\Attributes\DataProvider;
55
use RonasIT\Support\Tests\ModelTestState;
66
use RonasIT\Support\Traits\NovaTestTrait;
7-
@if($shouldUseStatus)
8-
use Symfony\Component\HttpFoundation\Response;
9-
@endif
107

118
class Nova{{$entity}}Test extends TestCase
129
{
@@ -31,27 +28,19 @@ public function testCreate(): void
3128

3229
$response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall({{$entity}}::class, $data);
3330

34-
@if($shouldUseStatus)
35-
$response->assertStatus(Response::HTTP_CREATED);
36-
@else
3731
$response->assertCreated();
38-
@endif
3932

4033
$this->assertEqualsFixture('create_{{$snake_entity}}_response.json', $response->json());
4134

42-
// TODO: Need to remove after first successful start
35+
// TODO: Need to remove last argument after first successful start
4336
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('create_{{$lower_entities}}_state.json', true);
4437
}
4538

4639
public function testCreateNoAuth(): void
4740
{
4841
$response = $this->novaCreateResourceAPICall({{$entity}}::class);
4942

50-
@if($shouldUseStatus)
51-
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
52-
@else
5343
$response->assertUnauthorized();
54-
@endif
5544

5645
self::${{$dromedary_entity}}State->assertNotChanged();
5746
}
@@ -60,13 +49,9 @@ public function testCreateValidationError(): void
6049
{
6150
$response = $this->novaActingAs(self::$user)->novaCreateResourceAPICall({{$entity}}::class);
6251

63-
@if($shouldUseStatus)
64-
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
65-
@else
6652
$response->assertUnprocessable();
67-
@endif
6853

69-
// TODO: Need to remove after first successful start
54+
// TODO: Need to remove last argument after first successful start
7055
$this->assertEqualsFixture('create_validation_response.json', $response->json(), true);
7156

7257
self::${{$dromedary_entity}}State->assertNotChanged();
@@ -78,13 +63,9 @@ public function testUpdate(): void
7863

7964
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 1, $data);
8065

81-
@if($shouldUseStatus)
82-
$response->assertStatus(Response::HTTP_NO_CONTENT);
83-
@else
8466
$response->assertNoContent();
85-
@endif
8667

87-
// TODO: Need to remove after first successful start
68+
// TODO: Need to remove last argument after first successful start
8869
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('update_{{$lower_entities}}_state.json', true);
8970
}
9071

@@ -94,150 +75,102 @@ public function testUpdateNotExists(): void
9475

9576
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 0, $data);
9677

97-
@if($shouldUseStatus)
98-
$response->assertStatus(Response::HTTP_NOT_FOUND);
99-
@else
10078
$response->assertNotFound();
101-
@endif
10279
}
10380

10481
public function testUpdateNoAuth(): void
10582
{
10683
$response = $this->novaUpdateResourceAPICall({{$entity}}::class, 1);
10784

108-
@if($shouldUseStatus)
109-
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
110-
@else
11185
$response->assertUnauthorized();
112-
@endif
11386
}
11487

11588
public function testUpdateValidationError(): void
11689
{
11790
$response = $this->novaActingAs(self::$user)->novaUpdateResourceAPICall({{$entity}}::class, 4);
11891

119-
@if($shouldUseStatus)
120-
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
121-
@else
12292
$response->assertUnprocessable();
123-
@endif
12493

125-
// TODO: Need to remove after first successful start
94+
// TODO: Need to remove last argument after first successful start
12695
$this->assertEqualsFixture('update_validation_response.json', $response->json(), true);
12796
}
12897

12998
public function testGetUpdatableFields(): void
13099
{
131100
$response = $this->novaActingAs(self::$user)->novaGetUpdatableFieldsAPICall({{$entity}}::class, 1);
132101

133-
@if($shouldUseStatus)
134-
$response->assertStatus(Response::HTTP_OK);
135-
@else
136102
$response->assertOk();
137-
@endif
138103

139-
// TODO: Need to remove after first successful start
104+
// TODO: Need to remove last argument after first successful start
140105
$this->assertEqualsFixture('get_updatable_fields_response.json', $response->json(), true);
141106
}
142107

143108
public function testDelete(): void
144109
{
145110
$response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{$entity}}::class, [1, 2]);
146111

147-
@if($shouldUseStatus)
148-
$response->assertStatus(Response::HTTP_OK);
149-
@else
150112
$response->assertOk();
151-
@endif
152113

153-
// TODO: Need to remove after first successful start
114+
// TODO: Need to remove last argument after first successful start
154115
self::${{$dromedary_entity}}State->assertChangesEqualsFixture('delete_{{$lower_entities}}_state.json', true);
155116
}
156117

157118
public function testDeleteNotExists(): void
158119
{
159120
$response = $this->novaActingAs(self::$user)->novaDeleteResourceAPICall({{$entity}}::class, [0]);
160121

161-
@if($shouldUseStatus)
162-
$response->assertStatus(Response::HTTP_NOT_FOUND);
163-
@else
164122
$response->assertNotFound();
165-
@endif
166123
}
167124

168125
public function testDeleteNoAuth(): void
169126
{
170127
$response = $this->novaDeleteResourceAPICall({{$entity}}::class, [1, 2]);
171128

172-
@if($shouldUseStatus)
173-
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
174-
@else
175129
$response->assertUnauthorized();
176-
@endif
177130
}
178131

179132
public function testGet(): void
180133
{
181134
$response = $this->novaActingAs(self::$user)->novaGetResourceAPICall({{$entity}}::class, 1);
182135

183-
@if($shouldUseStatus)
184-
$response->assertStatus(Response::HTTP_OK);
185-
@else
186136
$response->assertOk();
187-
@endif
188137

189-
// TODO: Need to remove after first successful start
138+
// TODO: Need to remove last argument after first successful start
190139
$this->assertEqualsFixture('get_{{$snake_entity}}_response.json', $response->json(), true);
191140
}
192141

193142
public function testGetNotExists(): void
194143
{
195144
$response = $this->novaActingAs(self::$user)->novaGetResourceAPICall({{$entity}}::class, 0);
196145

197-
@if($shouldUseStatus)
198-
$response->assertStatus(Response::HTTP_NOT_FOUND);
199-
@else
200146
$response->assertNotFound();
201-
@endif
202147
}
203148

204149
public function testGetNoAuth(): void
205150
{
206151
$response = $this->novaGetResourceAPICall({{$entity}}::class, 1);
207152

208-
@if($shouldUseStatus)
209-
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
210-
@else
211153
$response->assertUnauthorized();
212-
@endif
213154
}
214155

215156
public function testSearchUnauthorized(): void
216157
{
217158
$response = $this->novaSearchResourceAPICall({{$entity}}::class);
218159

219-
@if($shouldUseStatus)
220-
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
221-
@else
222160
$response->assertUnauthorized();
223-
@endif
224161
}
225162

226163
public function testGetFieldsVisibleOnCreate(): void
227164
{
228165
$response = $this->novaActingAs(self::$user)->novaGetCreationFieldsAPICall({{$entity}}::class);
229166

230-
@if($shouldUseStatus)
231-
$response->assertStatus(Response::HTTP_OK);
232-
@else
233167
$response->assertOk();
234-
@endif
235168

236-
// TODO: Need to remove after first successful start
169+
// TODO: Need to remove last argument after first successful start
237170
$this->assertEqualsFixture('get_fields_visible_on_create_response.json', $response->json(), true);
238171
}
239172

240-
public function getRun{{$entity}}ActionsData(): array
173+
public static function getRun{{$entity}}ActionsData(): array
241174
{
242175
return [
243176
@foreach($actions as $action)
@@ -252,82 +185,64 @@ public function getRun{{$entity}}ActionsData(): array
252185
];
253186
}
254187

255-
/**
256-
* @dataProvider getRun{{$entity}}ActionsData
257-
*/
188+
#[DataProvider('getRun{{$entity}}ActionsData')]
258189
public function testRun{{$entity}}Actions($action, $request, $state): void
259190
{
260191
$response = $this->novaActingAs(self::$user)->novaRunActionAPICall({{$entity}}::class, $action, $request);
261192

262-
@if($shouldUseStatus)
263-
$response->assertStatus(Response::HTTP_OK);
264-
@else
265193
$response->assertOk();
266-
@endif
267194

268195
$this->assertEmpty($response->getContent());
269196

270-
// TODO: Need to remove after first successful start
197+
// TODO: Need to remove last argument after first successful start
271198
self::${{$dromedary_entity}}State->assertChangesEqualsFixture($state, true);
272199
}
273200

274-
public function get{{$entity}}ActionsData(): array
201+
public static function get{{$entity}}ActionsData(): array
275202
{
276203
return [
277204
@foreach($actions as $action)
278205
[
279206
'resources' => [1, 2],
280-
'response_fixture' => 'get_{{$snake_entity}}_actions_{{$action['fixture']}}.json',
207+
'fixture' => 'get_{{$snake_entity}}_actions_{{$action['fixture']}}.json',
281208
],
282209
@endforeach
283210
];
284211
}
285212

286-
/**
287-
* @dataProvider get{{$entity}}ActionsData
288-
*/
289-
public function testGet{{$entity}}Actions(array $resources, string $responseFixture): void
213+
#[DataProvider('get{{$entity}}ActionsData')]
214+
public function testGet{{$entity}}Actions(array $resources, string $fixture): void
290215
{
291216
$response = $this->novaActingAs(self::$user)->novaGetActionsAPICall({{$entity}}::class, $resources);
292217

293-
@if($shouldUseStatus)
294-
$response->assertStatus(Response::HTTP_OK);
295-
@else
296218
$response->assertOk();
297-
@endif
298219

299-
// TODO: Need to remove after first successful start
300-
$this->assertEqualsFixture($responseFixture, $response->json(), true);
220+
// TODO: Need to remove last argument after first successful start
221+
$this->assertEqualsFixture($fixture, $response->json(), true);
301222
}
302223

303-
public function get{{$entity}}FiltersData(): array
224+
public static function get{{$entity}}FiltersData(): array
304225
{
305226
return [
306227
@foreach($filters as $filter)
307228
[
308229
'request' => [
309230
'{{$filter['name']}}' => $this->novaSearchParams(['search term']),
310231
],
311-
'response_fixture' => 'filter_{{$snake_entity}}_by_{{$filter['fixture_name']}}.json',
232+
'fixture' => 'filter_{{$snake_entity}}_by_{{$filter['fixture_name']}}.json',
312233
],
313234
@endforeach
314235
];
315236
}
316237

317-
/**
318-
* @dataProvider get{{$entity}}FiltersData
319-
*/
320-
public function testFilter{{$entity}}(array $request, string $responseFixture): void
238+
#[DataProvider('get{{$entity}}FiltersData')]
239+
public function testFilter{{$entity}}(array $request, string $fixture): void
321240
{
322241
$response = $this->novaActingAs(self::$user)->novaSearchResourceAPICall({{$entity}}::class, $request);
323242

324-
@if($shouldUseStatus)
325-
$response->assertStatus(Response::HTTP_OK);
326-
@else
327243
$response->assertOk();
328-
@endif
329244

330-
// TODO: Need to remove after first successful start
331-
$this->assertEqualsFixture($responseFixture, $response->json(), true);
245+
// TODO: Need to remove last argument after first successful start
246+
$this->assertEqualsFixture($fixture, $response->json(), true);
332247
}
333248
}

0 commit comments

Comments
 (0)