NDM
NDM

Reputation: 6840

Symfony 2.6 overrides PHPUnit_Framework_Error

I have a unit tested application which we have updated from symfony 2.3 to 2.6. We followed all upgrading docs and had to change only some minor stuff. Everything is working perfectly, except for the PHPUnit tests.

We have 2 seperate runs, one for only testing the entity classes, which is fired on a pre-commit hook. and a second one which runs the full suite, with database setups and the whole nine yards.

Now since the upgrade to 2.6, the PHPUnit_Framework_Error thrown in the unit tests have been replaced by Symfony's Symfony\Component\Debug\Exception\ContextErrorException, this failing all tests like this:

/**
 * @dataProvider objectTestDataProvider
 * @expectedException \PHPUnit_Framework_Error
 */
public function testCanNotSetClientToArbitraryValue($value)

Now I do not want to change this into the new Exception since running the entity-only test suite does not depend on symfony components, thus symfony is not loaded, thus the errors are the regular PHPUnit_Framework_Error so changing it makes these tests fail.

In other words, when I run one test class it works, once a symfony dependent test is run, it fails:

# runs perfectly
phpunit -c app/phpunit.xml --debug src/My/Bundle/Tests/Entity
# fails when reaching the tests that ran perfectly in previous command
phpunit -c app/phpunit.xml --debug

This new ErrorHandler seems undocumented, I couldnt find much about it in google except for the pull request and this small article

I've tried:

edit:

On request by @cerad I've tried to isolate the tests to try and reproduce the code with as little as possible, Ive managed to reproduce with 4 tests:

class MyControllerTest extends WebTestCase
{
    public function testRoutesLoaded_1()
    {
        $client = self::createClient();

        /** @var Router $router */
        $router = $client->getKernel()->getContainer()->get('router');
        $this->assertEquals('/menu', $router->generate('front_menu'));
    }

    /**
     * @expectedException \PHPUnit_Framework_Error
     */
    public function testCreateOrder_1()
    {
        new Order(); // required parameter missing
    }

    public function testRoutesLoaded_2()
    {
        $client = $this->createNewFrontClient();

        /** @var Router $router */
        $router = $client->getKernel()->getContainer()->get('router');
        $this->assertEquals('/menu', $router->generate('front_menu'));
    }

    /**
     * @expectedException \PHPUnit_Framework_Error
     */
    public function testCreateOrder_2()
    {
        new Order(); // required parameter missing
    }
}

As you can see, I just run the same exact test 2 times, but still the last one results in an error:

MyControllerTest::testCreateOrder_2 Failed asserting that exception of type "Symfony\Component\Debug\Exception\ContextErrorException" matches expected exception "\PHPUnit_Framework_Error"

Upvotes: 4

Views: 1008

Answers (1)

NDM
NDM

Reputation: 6840

Since I did not get any replies here, I posted an issue on Symfony's github and they confirmed this was incorrect behavior.

The issue was resolved and is merged in 2.6-dev.

Upvotes: 5

Related Questions