Skip to content

WebTestCase: a 500 error doesn't make the PHPUnit test to fail #33305

Closed
@dunglas

Description

@dunglas

Symfony version(s) affected: 4.3 (at least)

Description

In the context of a functional test, if the tested page throws an exception, it is silenced by Symfony. Instead of having a failing PHPUnit test, the error page (with the ghost) is generated and no exceptions are thrown. This lead to uncaught exceptions, or cryptic errors at the following assertion.

How to reproduce

<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ItemControllerTest extends WebTestCase
{
    public function testCreateItem(): void
    {
        $client = static::createClient();
        $client->request('GET', '/page-throwing-an-exception');
        // This test is green, but shouldn't
}

Possible Solution

Throw instead of generating the error page when in the context of a functional test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions