Skip to content

Commit 1d1b3e4

Browse files
authored
Merge pull request #354 from jolicode/feat/apip5
feat: support api platform 5
2 parents 1bc9c70 + 009430b commit 1d1b3e4

6 files changed

Lines changed: 42 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
- Support API Platform 5 alongside API Platform 4
12+
1013
## [10.3.0] - 2026-09-16
1114

1215
### Added

‎castor.composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"castor-php/php-qa": "dev-main"
3+
"castor-php/php-qa": "^0.3.4"
44
}
55
}

‎castor.composer.lock‎

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎castor.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use function Castor\PHPQa\phpstan;
1212
use function Castor\run;
1313

14+
defined('CASTOR_USE_CHDIR') || define('CASTOR_USE_CHDIR', true);
15+
1416
const PHP_CS_FIXER_VERSION = '3.95.1';
1517

1618
#[AsTask('cs:check', namespace: 'qa', description: 'Check for coding standards without fixing them')]

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"symfony/type-info": "^7.4 || ^8.0"
3333
},
3434
"require-dev": {
35-
"api-platform/core": "^4.2",
35+
"api-platform/core": "^4.2 || ^5.0",
3636
"doctrine/collections": "^2.4",
3737
"doctrine/doctrine-bundle": "^3.0",
3838
"doctrine/inflector": "^2.1",
3939
"doctrine/orm": "^3.5",
4040
"matthiasnoback/symfony-dependency-injection-test": "^6.1",
41-
"moneyphp/money": "^3.3.2",
41+
"moneyphp/money": "^3.3.2 || ^4.0",
4242
"phpunit/phpunit": "^13.0",
4343
"symfony/browser-kit": "^7.4 || ^8.0",
4444
"symfony/console": "^7.4 || ^8.0",

‎tests/Bundle/ApiPlatformTest.php‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
namespace AutoMapper\Tests\Bundle;
66

7-
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
87
use Symfony\Component\Filesystem\Filesystem;
8+
use Symfony\Contracts\HttpClient\ResponseInterface;
99

10-
if (!class_exists(ApiTestCase::class)) {
10+
// API Platform 5 moved the test case out of the Symfony bundle namespace and deprecated the old one
11+
$baseApiTestCase = match (true) {
12+
class_exists(\ApiPlatform\Test\ApiTestCase::class) => \ApiPlatform\Test\ApiTestCase::class,
13+
class_exists(\ApiPlatform\Symfony\Bundle\Test\ApiTestCase::class) => \ApiPlatform\Symfony\Bundle\Test\ApiTestCase::class,
14+
default => null,
15+
};
16+
17+
if (null === $baseApiTestCase) {
1118
class ApiPlatformTest extends \PHPUnit\Framework\TestCase
1219
{
1320
protected static function createClient(): void
@@ -19,7 +26,9 @@ protected static function createClient(): void
1926
return;
2027
}
2128

22-
class ApiPlatformTest extends ApiTestCase
29+
class_alias($baseApiTestCase, BaseApiTestCase::class);
30+
31+
class ApiPlatformTest extends BaseApiTestCase
2332
{
2433
protected function setUp(): void
2534
{
@@ -70,7 +79,7 @@ public function testGetBookCollectionOnApip(): void
7079
$response = static::createClient()->request('GET', '/books.jsonld');
7180

7281
$this->assertResponseIsSuccessful();
73-
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
82+
$this->assertContentTypeSame($response, 'application/ld+json');
7483

7584
$this->assertJsonContains([
7685
'@context' => '/contexts/Book',
@@ -89,10 +98,10 @@ public function testGetBookCollectionOnApip(): void
8998

9099
public function testGetBook(): void
91100
{
92-
static::createClient()->request('GET', '/books/1.jsonld');
101+
$response = static::createClient()->request('GET', '/books/1.jsonld');
93102

94103
$this->assertResponseIsSuccessful();
95-
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
104+
$this->assertContentTypeSame($response, 'application/ld+json');
96105

97106
$this->assertJsonContains([
98107
'@context' => '/contexts/Book',
@@ -113,7 +122,7 @@ public function testCreateBook(): void
113122
]]);
114123

115124
$this->assertResponseStatusCodeSame(201);
116-
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
125+
$this->assertContentTypeSame($response, 'application/ld+json');
117126
$this->assertJsonContains([
118127
'@context' => '/contexts/Book',
119128
'@type' => 'Book',
@@ -166,6 +175,16 @@ public function testCreateWithIriRelationInPlainJson(): void
166175
$this->assertSame('/books/1', $response->toArray()['book']);
167176
}
168177

178+
/**
179+
* API Platform 5 no longer appends "; charset=utf-8" to JSON based media types.
180+
*/
181+
private function assertContentTypeSame(ResponseInterface $response, string $mimeType): void
182+
{
183+
$contentType = $response->getHeaders(false)['content-type'][0] ?? '';
184+
185+
$this->assertSame($mimeType, explode(';', $contentType, 2)[0]);
186+
}
187+
169188
protected function tearDown(): void
170189
{
171190
parent::tearDown();

0 commit comments

Comments
 (0)