[Bug]: Upgrade to 4.26.0 breaks phpunit-tests
Closed this issue · 2 comments
Version
4.26.0
Description
Hey! After upgrading from 4.25.2 to 4.26.1 (Checked with 4.25.0 aswell), the controller tests fail with phpunit 11, when Attributes are being nested. (Symfony: 7.0.6, PHP 8.3)
Reproduce:
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
#[AsController]
final class SimpleController
{
#[OA\Get(
operationId: 'simpleController',
description: 'A simple Controller',
summary: 'Returns a simple response.',
tags: ['Simple'],
responses: [
new OA\Response(
response: 200,
description: 'The Response attribute nested inside the Get attribute.',
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(type: 'string', example: 'simple'),
example: 'simple'
)
),
]
)]
#[Route(path: '/simple', name: 'simple', methods: ['GET'], format: 'json')]
public function __invoke(): Response
{
return new JsonResponse('simple');
}
}
The failing test:
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class SimpleControllerTest extends WebTestCase
{
public function testSimpleController(): void
{
$client = self::createClient();
$client->request('GET', '/simple');
self::assertResponseIsSuccessful();
self::assertSame('"simple"', $client->getResponse()->getContent());
}
}
I was not able to pinpoint the exact line where the code breaks, was only able to observe that the test works when excluding the "responses" array from the Get
attribute. When moving the Response
to a separate attribute, it also only works when removing the MediaType
from it.
The logged exception was also not very helpful here (for me at least):
Uncaught PHP Exception AssertionError: "assert(isset($trace[0]['file']))"
I hope you have an idea what the issue might be and that my example is sufficient to reproduce the bug.
Cheers!
Additional context
No response
Maybe related? zircote/swagger-php#1579
Yes, updating zircote/swagger-php to 4.9.2 solved the issue!