14
14
use App \Tests \Api \Admin \Trait \UsersDataProviderTrait ;
15
15
use App \Tests \Api \Trait \SecurityTrait ;
16
16
use App \Tests \Api \Trait \SerializerTrait ;
17
+ use PHPUnit \Framework \Attributes \DataProvider ;
17
18
use Symfony \Component \HttpFoundation \Response ;
18
19
use Symfony \Component \Mercure \Update ;
19
20
use Zenstruck \Foundry \FactoryCollection ;
20
21
use Zenstruck \Foundry \Test \Factories ;
21
22
use Zenstruck \Foundry \Test \ResetDatabase ;
23
+ use PHPUnit \Framework \Attributes \Test ;
22
24
23
25
final class BookTest extends ApiTestCase
24
26
{
@@ -35,11 +37,8 @@ protected function setup(): void
35
37
$ this ->client = self ::createClient ();
36
38
}
37
39
38
- /**
39
- * @dataProvider getNonAdminUsers
40
- *
41
- * @test
42
- */
40
+ #[Test]
41
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
43
42
public function asNonAdminUserICannotGetACollectionOfBooks (int $ expectedCode , string $ hydraDescription , ?UserFactory $ userFactory ): void
44
43
{
45
44
$ options = [];
@@ -62,11 +61,8 @@ public function asNonAdminUserICannotGetACollectionOfBooks(int $expectedCode, st
62
61
]);
63
62
}
64
63
65
- /**
66
- * @dataProvider getUrls
67
- *
68
- * @test
69
- */
64
+ #[Test]
65
+ #[DataProvider(methodName: 'getUrls ' )]
70
66
public function asAdminUserICanGetACollectionOfBooks (FactoryCollection $ factory , string $ url , int $ hydraTotalItems , int $ itemsPerPage = null ): void
71
67
{
72
68
// Cannot use Factory as data provider because BookFactory has a service dependency
@@ -132,9 +128,7 @@ public static function getUrls(): iterable
132
128
];
133
129
}
134
130
135
- /**
136
- * @test
137
- */
131
+ #[Test]
138
132
public function asAdminUserICanGetACollectionOfBooksOrderedByTitle (): void
139
133
{
140
134
BookFactory::createOne (['title ' => 'Hyperion ' ]);
@@ -155,11 +149,8 @@ public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
155
149
self ::assertMatchesJsonSchema (file_get_contents (__DIR__ . '/schemas/Book/collection.json ' ));
156
150
}
157
151
158
- /**
159
- * @dataProvider getAllUsers
160
- *
161
- * @test
162
- */
152
+ #[Test]
153
+ #[DataProvider(methodName: 'getAllUsers ' )]
163
154
public function asAnyUserICannotGetAnInvalidBook (?UserFactory $ userFactory ): void
164
155
{
165
156
BookFactory::createOne ();
@@ -184,11 +175,8 @@ public static function getAllUsers(): iterable
184
175
yield [UserFactory::new (['roles ' => ['ROLE_ADMIN ' ]])];
185
176
}
186
177
187
- /**
188
- * @dataProvider getNonAdminUsers
189
- *
190
- * @test
191
- */
178
+ #[Test]
179
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
192
180
public function asNonAdminUserICannotGetABook (int $ expectedCode , string $ hydraDescription , ?UserFactory $ userFactory ): void
193
181
{
194
182
$ book = BookFactory::createOne ();
@@ -213,11 +201,8 @@ public function asNonAdminUserICannotGetABook(int $expectedCode, string $hydraDe
213
201
]);
214
202
}
215
203
216
- /**
217
- * @dataProvider getNonAdminUsers
218
- *
219
- * @test
220
- */
204
+ #[Test]
205
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
221
206
public function asAdminUserICanGetABook (): void
222
207
{
223
208
$ book = BookFactory::createOne ();
@@ -240,11 +225,8 @@ public function asAdminUserICanGetABook(): void
240
225
self ::assertMatchesJsonSchema (file_get_contents (__DIR__ . '/schemas/Book/item.json ' ));
241
226
}
242
227
243
- /**
244
- * @dataProvider getNonAdminUsers
245
- *
246
- * @test
247
- */
228
+ #[Test]
229
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
248
230
public function asNonAdminUserICannotCreateABook (int $ expectedCode , string $ hydraDescription , ?UserFactory $ userFactory ): void
249
231
{
250
232
$ options = [];
@@ -276,11 +258,8 @@ public function asNonAdminUserICannotCreateABook(int $expectedCode, string $hydr
276
258
]);
277
259
}
278
260
279
- /**
280
- * @dataProvider getInvalidDataOnCreate
281
- *
282
- * @test
283
- */
261
+ #[Test]
262
+ #[DataProvider(methodName: 'getInvalidDataOnCreate ' )]
284
263
public function asAdminUserICannotCreateABookWithInvalidData (array $ data , int $ statusCode , array $ expected ): void
285
264
{
286
265
$ token = $ this ->generateToken ([
@@ -302,7 +281,7 @@ public function asAdminUserICannotCreateABookWithInvalidData(array $data, int $s
302
281
self ::assertJsonContains ($ expected );
303
282
}
304
283
305
- public function getInvalidDataOnCreate (): iterable
284
+ public static function getInvalidDataOnCreate (): iterable
306
285
{
307
286
yield 'no data ' => [
308
287
[],
@@ -322,7 +301,7 @@ public function getInvalidDataOnCreate(): iterable
322
301
],
323
302
],
324
303
];
325
- yield from $ this -> getInvalidData ();
304
+ yield from self :: getInvalidData ();
326
305
}
327
306
328
307
public static function getInvalidData (): iterable
@@ -385,9 +364,8 @@ public static function getInvalidData(): iterable
385
364
/**
386
365
* @group apiCall
387
366
* @group mercure
388
- *
389
- * @test
390
367
*/
368
+ #[Test]
391
369
public function asAdminUserICanCreateABook (): void
392
370
{
393
371
$ token = $ this ->generateToken ([
@@ -443,11 +421,8 @@ public function asAdminUserICanCreateABook(): void
443
421
);
444
422
}
445
423
446
- /**
447
- * @dataProvider getNonAdminUsers
448
- *
449
- * @test
450
- */
424
+ #[Test]
425
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
451
426
public function asNonAdminUserICannotUpdateBook (int $ expectedCode , string $ hydraDescription , ?UserFactory $ userFactory ): void
452
427
{
453
428
$ book = BookFactory::createOne ();
@@ -481,9 +456,7 @@ public function asNonAdminUserICannotUpdateBook(int $expectedCode, string $hydra
481
456
]);
482
457
}
483
458
484
- /**
485
- * @test
486
- */
459
+ #[Test]
487
460
public function asAdminUserICannotUpdateAnInvalidBook (): void
488
461
{
489
462
BookFactory::createOne ();
@@ -506,11 +479,8 @@ public function asAdminUserICannotUpdateAnInvalidBook(): void
506
479
self ::assertResponseStatusCodeSame (Response::HTTP_NOT_FOUND );
507
480
}
508
481
509
- /**
510
- * @dataProvider getInvalidData
511
- *
512
- * @test
513
- */
482
+ #[Test]
483
+ #[DataProvider(methodName: 'getInvalidData ' )]
514
484
public function asAdminUserICannotUpdateABookWithInvalidData (array $ data , int $ statusCode , array $ expected ): void
515
485
{
516
486
$ book = BookFactory::createOne ();
@@ -537,9 +507,8 @@ public function asAdminUserICannotUpdateABookWithInvalidData(array $data, int $s
537
507
/**
538
508
* @group apiCall
539
509
* @group mercure
540
- *
541
- * @test
542
510
*/
511
+ #[Test]
543
512
public function asAdminUserICanUpdateABook (): void
544
513
{
545
514
$ book = BookFactory::createOne ([
@@ -599,11 +568,8 @@ public function asAdminUserICanUpdateABook(): void
599
568
);
600
569
}
601
570
602
- /**
603
- * @dataProvider getNonAdminUsers
604
- *
605
- * @test
606
- */
571
+ #[Test]
572
+ #[DataProvider(methodName: 'getNonAdminUsers ' )]
607
573
public function asNonAdminUserICannotDeleteABook (int $ expectedCode , string $ hydraDescription , ?UserFactory $ userFactory ): void
608
574
{
609
575
$ book = BookFactory::createOne ();
@@ -628,9 +594,7 @@ public function asNonAdminUserICannotDeleteABook(int $expectedCode, string $hydr
628
594
]);
629
595
}
630
596
631
- /**
632
- * @test
633
- */
597
+ #[Test]
634
598
public function asAdminUserICannotDeleteAnInvalidBook (): void
635
599
{
636
600
BookFactory::createOne ();
@@ -646,9 +610,8 @@ public function asAdminUserICannotDeleteAnInvalidBook(): void
646
610
647
611
/**
648
612
* @group mercure
649
- *
650
- * @test
651
613
*/
614
+ #[Test]
652
615
public function asAdminUserICanDeleteABook (): void
653
616
{
654
617
$ book = BookFactory::createOne (['title ' => 'Hyperion ' ]);
0 commit comments