Skip to content

Commit 2897cc6

Browse files
chore: migrate to phpunit 10
1 parent 3480b78 commit 2897cc6

22 files changed

+270
-446
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction
6565
-
6666
name: Run PHPUnit
67-
run: docker compose exec -T php bin/phpunit
67+
run: docker compose exec -T php vendor/bin/phpunit
6868
-
6969
name: Doctrine Schema Validator
7070
run: docker compose exec -T php bin/console -e test doctrine:schema:validate

api/.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
/.php-cs-fixer.cache
1616
###< friendsofphp/php-cs-fixer ###
1717

18-
###> symfony/phpunit-bridge ###
19-
.phpunit.result.cache
20-
/phpunit.xml
21-
###< symfony/phpunit-bridge ###
22-
2318
###> phpstan/phpstan ###
2419
phpstan.neon
2520
###< phpstan/phpstan ###
21+
22+
###> phpunit/phpunit ###
23+
/phpunit.xml
24+
.phpunit.result.cache
25+
###< phpunit/phpunit ###

api/phpstan.dist.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ parameters:
1414
- var/cache/dev/Symfony/Config
1515
bootstrapFiles:
1616
- vendor/autoload.php
17-
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
1817
- src/Kernel.php
1918
ignoreErrors:
2019
- message: '#no (?:return|value) type specified in iterable type array\.#'

api/phpunit.xml.dist

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
backupGlobals="false"
77
colors="true"
88
bootstrap="tests/bootstrap.php"
9-
convertDeprecationsToExceptions="false"
9+
cacheDirectory=".phpunit.cache"
1010
>
1111
<php>
1212
<ini name="display_errors" value="1" />
1313
<ini name="error_reporting" value="-1" />
1414
<server name="APP_ENV" value="test" force="true" />
1515
<server name="APP_DEBUG" value="false" force="true" />
1616
<server name="SHELL_VERBOSITY" value="-1" />
17-
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
18-
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
1917
</php>
2018

2119
<testsuites>
@@ -24,17 +22,13 @@
2422
</testsuite>
2523
</testsuites>
2624

27-
<coverage processUncoveredFiles="true">
25+
<source>
2826
<include>
2927
<directory suffix=".php">src</directory>
3028
</include>
31-
</coverage>
32-
33-
<listeners>
34-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
35-
</listeners>
29+
</source>
3630

3731
<extensions>
38-
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
32+
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
3933
</extensions>
4034
</phpunit>

api/symfony.lock

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@
199199
"phpstan.dist.neon"
200200
]
201201
},
202+
"phpunit/phpunit": {
203+
"version": "10.5",
204+
"recipe": {
205+
"repo": "github.com/symfony/recipes",
206+
"branch": "main",
207+
"version": "9.6",
208+
"ref": "7364a21d87e658eb363c5020c072ecfdc12e2326"
209+
},
210+
"files": [
211+
".env.test",
212+
"phpunit.xml.dist",
213+
"tests/bootstrap.php"
214+
]
215+
},
202216
"psr/cache": {
203217
"version": "3.0.0"
204218
},
@@ -377,21 +391,6 @@
377391
"symfony/password-hasher": {
378392
"version": "v6.0.2"
379393
},
380-
"symfony/phpunit-bridge": {
381-
"version": "6.3",
382-
"recipe": {
383-
"repo": "github.com/symfony/recipes",
384-
"branch": "main",
385-
"version": "6.3",
386-
"ref": "01dfaa98c58f7a7b5a9b30e6edb7074af7ed9819"
387-
},
388-
"files": [
389-
".env.test",
390-
"bin/phpunit",
391-
"phpunit.xml.dist",
392-
"tests/bootstrap.php"
393-
]
394-
},
395394
"symfony/polyfill-php70": {
396395
"version": "v1.20.0"
397396
},

api/tests/Api/Admin/BookTest.php

Lines changed: 30 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
use App\Tests\Api\Admin\Trait\UsersDataProviderTrait;
1515
use App\Tests\Api\Trait\SecurityTrait;
1616
use App\Tests\Api\Trait\SerializerTrait;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use Symfony\Component\HttpFoundation\Response;
1819
use Symfony\Component\Mercure\Update;
1920
use Zenstruck\Foundry\FactoryCollection;
2021
use Zenstruck\Foundry\Test\Factories;
2122
use Zenstruck\Foundry\Test\ResetDatabase;
23+
use PHPUnit\Framework\Attributes\Test;
2224

2325
final class BookTest extends ApiTestCase
2426
{
@@ -35,11 +37,8 @@ protected function setup(): void
3537
$this->client = self::createClient();
3638
}
3739

38-
/**
39-
* @dataProvider getNonAdminUsers
40-
*
41-
* @test
42-
*/
40+
#[Test]
41+
#[DataProvider(methodName: 'getNonAdminUsers')]
4342
public function asNonAdminUserICannotGetACollectionOfBooks(int $expectedCode, string $hydraDescription, ?UserFactory $userFactory): void
4443
{
4544
$options = [];
@@ -62,11 +61,8 @@ public function asNonAdminUserICannotGetACollectionOfBooks(int $expectedCode, st
6261
]);
6362
}
6463

65-
/**
66-
* @dataProvider getUrls
67-
*
68-
* @test
69-
*/
64+
#[Test]
65+
#[DataProvider(methodName: 'getUrls')]
7066
public function asAdminUserICanGetACollectionOfBooks(FactoryCollection $factory, string $url, int $hydraTotalItems, int $itemsPerPage = null): void
7167
{
7268
// Cannot use Factory as data provider because BookFactory has a service dependency
@@ -132,9 +128,7 @@ public static function getUrls(): iterable
132128
];
133129
}
134130

135-
/**
136-
* @test
137-
*/
131+
#[Test]
138132
public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
139133
{
140134
BookFactory::createOne(['title' => 'Hyperion']);
@@ -155,11 +149,8 @@ public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
155149
self::assertMatchesJsonSchema(file_get_contents(__DIR__ . '/schemas/Book/collection.json'));
156150
}
157151

158-
/**
159-
* @dataProvider getAllUsers
160-
*
161-
* @test
162-
*/
152+
#[Test]
153+
#[DataProvider(methodName: 'getAllUsers')]
163154
public function asAnyUserICannotGetAnInvalidBook(?UserFactory $userFactory): void
164155
{
165156
BookFactory::createOne();
@@ -184,11 +175,8 @@ public static function getAllUsers(): iterable
184175
yield [UserFactory::new(['roles' => ['ROLE_ADMIN']])];
185176
}
186177

187-
/**
188-
* @dataProvider getNonAdminUsers
189-
*
190-
* @test
191-
*/
178+
#[Test]
179+
#[DataProvider(methodName: 'getNonAdminUsers')]
192180
public function asNonAdminUserICannotGetABook(int $expectedCode, string $hydraDescription, ?UserFactory $userFactory): void
193181
{
194182
$book = BookFactory::createOne();
@@ -213,11 +201,8 @@ public function asNonAdminUserICannotGetABook(int $expectedCode, string $hydraDe
213201
]);
214202
}
215203

216-
/**
217-
* @dataProvider getNonAdminUsers
218-
*
219-
* @test
220-
*/
204+
#[Test]
205+
#[DataProvider(methodName: 'getNonAdminUsers')]
221206
public function asAdminUserICanGetABook(): void
222207
{
223208
$book = BookFactory::createOne();
@@ -240,11 +225,8 @@ public function asAdminUserICanGetABook(): void
240225
self::assertMatchesJsonSchema(file_get_contents(__DIR__ . '/schemas/Book/item.json'));
241226
}
242227

243-
/**
244-
* @dataProvider getNonAdminUsers
245-
*
246-
* @test
247-
*/
228+
#[Test]
229+
#[DataProvider(methodName: 'getNonAdminUsers')]
248230
public function asNonAdminUserICannotCreateABook(int $expectedCode, string $hydraDescription, ?UserFactory $userFactory): void
249231
{
250232
$options = [];
@@ -276,11 +258,8 @@ public function asNonAdminUserICannotCreateABook(int $expectedCode, string $hydr
276258
]);
277259
}
278260

279-
/**
280-
* @dataProvider getInvalidDataOnCreate
281-
*
282-
* @test
283-
*/
261+
#[Test]
262+
#[DataProvider(methodName: 'getInvalidDataOnCreate')]
284263
public function asAdminUserICannotCreateABookWithInvalidData(array $data, int $statusCode, array $expected): void
285264
{
286265
$token = $this->generateToken([
@@ -302,7 +281,7 @@ public function asAdminUserICannotCreateABookWithInvalidData(array $data, int $s
302281
self::assertJsonContains($expected);
303282
}
304283

305-
public function getInvalidDataOnCreate(): iterable
284+
public static function getInvalidDataOnCreate(): iterable
306285
{
307286
yield 'no data' => [
308287
[],
@@ -322,7 +301,7 @@ public function getInvalidDataOnCreate(): iterable
322301
],
323302
],
324303
];
325-
yield from $this->getInvalidData();
304+
yield from self::getInvalidData();
326305
}
327306

328307
public static function getInvalidData(): iterable
@@ -385,9 +364,8 @@ public static function getInvalidData(): iterable
385364
/**
386365
* @group apiCall
387366
* @group mercure
388-
*
389-
* @test
390367
*/
368+
#[Test]
391369
public function asAdminUserICanCreateABook(): void
392370
{
393371
$token = $this->generateToken([
@@ -443,11 +421,8 @@ public function asAdminUserICanCreateABook(): void
443421
);
444422
}
445423

446-
/**
447-
* @dataProvider getNonAdminUsers
448-
*
449-
* @test
450-
*/
424+
#[Test]
425+
#[DataProvider(methodName: 'getNonAdminUsers')]
451426
public function asNonAdminUserICannotUpdateBook(int $expectedCode, string $hydraDescription, ?UserFactory $userFactory): void
452427
{
453428
$book = BookFactory::createOne();
@@ -481,9 +456,7 @@ public function asNonAdminUserICannotUpdateBook(int $expectedCode, string $hydra
481456
]);
482457
}
483458

484-
/**
485-
* @test
486-
*/
459+
#[Test]
487460
public function asAdminUserICannotUpdateAnInvalidBook(): void
488461
{
489462
BookFactory::createOne();
@@ -506,11 +479,8 @@ public function asAdminUserICannotUpdateAnInvalidBook(): void
506479
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
507480
}
508481

509-
/**
510-
* @dataProvider getInvalidData
511-
*
512-
* @test
513-
*/
482+
#[Test]
483+
#[DataProvider(methodName: 'getInvalidData')]
514484
public function asAdminUserICannotUpdateABookWithInvalidData(array $data, int $statusCode, array $expected): void
515485
{
516486
$book = BookFactory::createOne();
@@ -537,9 +507,8 @@ public function asAdminUserICannotUpdateABookWithInvalidData(array $data, int $s
537507
/**
538508
* @group apiCall
539509
* @group mercure
540-
*
541-
* @test
542510
*/
511+
#[Test]
543512
public function asAdminUserICanUpdateABook(): void
544513
{
545514
$book = BookFactory::createOne([
@@ -599,11 +568,8 @@ public function asAdminUserICanUpdateABook(): void
599568
);
600569
}
601570

602-
/**
603-
* @dataProvider getNonAdminUsers
604-
*
605-
* @test
606-
*/
571+
#[Test]
572+
#[DataProvider(methodName: 'getNonAdminUsers')]
607573
public function asNonAdminUserICannotDeleteABook(int $expectedCode, string $hydraDescription, ?UserFactory $userFactory): void
608574
{
609575
$book = BookFactory::createOne();
@@ -628,9 +594,7 @@ public function asNonAdminUserICannotDeleteABook(int $expectedCode, string $hydr
628594
]);
629595
}
630596

631-
/**
632-
* @test
633-
*/
597+
#[Test]
634598
public function asAdminUserICannotDeleteAnInvalidBook(): void
635599
{
636600
BookFactory::createOne();
@@ -646,9 +610,8 @@ public function asAdminUserICannotDeleteAnInvalidBook(): void
646610

647611
/**
648612
* @group mercure
649-
*
650-
* @test
651613
*/
614+
#[Test]
652615
public function asAdminUserICanDeleteABook(): void
653616
{
654617
$book = BookFactory::createOne(['title' => 'Hyperion']);

0 commit comments

Comments
 (0)