Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Upgrade to 4.26.0 breaks phpunit-tests #2278

Closed
mazumba-nx opened this issue Apr 22, 2024 · 2 comments
Closed

[Bug]: Upgrade to 4.26.0 breaks phpunit-tests #2278

mazumba-nx opened this issue Apr 22, 2024 · 2 comments
Labels

Comments

@mazumba-nx
Copy link

mazumba-nx commented Apr 22, 2024

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

@mazumba-nx mazumba-nx added the bug label Apr 22, 2024
@dschuld-nx
Copy link

Maybe related? zircote/swagger-php#1579

@mazumba-nx
Copy link
Author

Yes, updating zircote/swagger-php to 4.9.2 solved the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants