3

With my symfony 2 application, i am using phpunit to test if each controller's action response's status code is the expected one.

When not, how can I have phpunit display the error message that comes with the exception, or best, simulate a profiler exception page ?

The reason for this is I have an action returning a 500 code in phpunit but which loads just fine in my browser.

My code :

/**
 * @dataProvider urlProvider
 * @param $url
 */
public function testPageIsSuccessful($url)
{
    $client = self::createClient(array(), array(
            'PHP_AUTH_USER' => 'superadmin',
            'PHP_AUTH_PW'   => '587010',
        ));
    $client->followRedirects();
    $client->request('GET', $url);
    var_dump($url);
    $this->assertEquals(200, $client->getResponse()->getStatusCode());
}

Thanks !

2
  • 1
    Have you cleared your cache? If you don't, you near always get a 500 error Commented Apr 15, 2015 at 15:15
  • I saw you proposed edit to my answer, you can add it in another answer if you think it can help other users (but you should remove specific code like $foodMeUp). Commented Apr 17, 2015 at 13:37

3 Answers 3

3

You could use xDebug to debug your code.

  1. run export XDEBUG_CONFIG=1 from console or turn on xdebug cookie in your browser
  2. turn on xdebug listener in your IDE.
  3. place breakpoint on your test method, or app.php or controller's action, you want to debug.
  4. run your tests from console or reload page in browser
  5. debug your application until you get an exception.

Instructions, how to set up xDebug are on http://xdebug.org/

In Ubuntu you could run:

sudo apt-get install php5-xdebug
Sign up to request clarification or add additional context in comments.

Comments

2

You can get the rendered HTML in your test with the following code:

die($client->getResponse()->getContent());

You have to put this just before the failing test and PHPUnit will display the HTML code. It's not convenient but it helped me many times.

1 Comment

trying reading html from console ... it can be done but it's an overkill
1

A better solution is to check the test log file and grep for CRITICAL or EXCEPTION tail -f var/logs/test.log | grep exception

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.