Symfony 2.6 overrides PHPUnit_Framework_Error

I have a test application that we upgraded from Symfony 2.3 to 2.6. We kept track of all document updates and needed to change only a few minor things. Everything works fine except for PHPUnit tests.

We have 2 separate runs, one for testing only entity classes that runs on the pre-commit hook. and the second, which runs the full set, with database settings and as many as nine yards.

Now, starting with the upgrade to version 2.6, the tags PHPUnit_Framework_Errorthat were added to the unit tests were replaced with Symfony Symfony\Component\Debug\Exception\ContextErrorException, which failed to run all the tests as follows:

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

Now I do not want to change this to a new exception, since running an entity-dependent test suite does not depend on symfony components, so symfony does not load, so errors are regular PHPUnit_Framework_Error, so changing them makes these tests fail.

In other words, when I run one test class, it works, as soon as a symfony dependent test runs, 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 to be undocumented, I couldn't find much about it on google except pull request, and this little article

I tried:

  • setting an environment variable SYMFONY_DEBUG=0, but that doesn't seem to make any difference.
  • adding parameter debug.error_handler.throw_at: 0to test_config.yml file

change

@cerad , , Ive 4 :

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
    }
}

, 2 , :

MyControllerTest:: testCreateOrder_2 , "Symfony\Component\Debug\Exception\ContextErrorException" "\ PHPUnit_Framework_Error"

+4
1
+5

All Articles