草庐IT

php - symfony2 phpunit : how to get exception message when status code is not expected one

coder 2024-04-30 原文

在我的 symfony 2 应用程序中,我使用 phpunit 来测试每个 Controller 的 Action 响应的状态代码是否是预期的。

如果不是,我如何让 phpunit 显示异常附带的错误消息,或者最好模拟一个探查器异常页面?

这是因为我在 phpunit 中有一个返回 500 代码的操作,但它在我的浏览器中加载得很好。

我的代码:

/**
 * @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());
}

谢谢!

最佳答案

您可以使用 xDebug 来调试您的代码。

  1. 从控制台运行 export XDEBUG_CONFIG=1 或在浏览器中打开 xdebug cookie
  2. 在您的 IDE 中打开 xdebug 监听器。
  3. 在您要调试的测试方法或app.php 或 Controller 的操作上放置断点。
  4. 从控制台运行测试或在浏览器中重新加载页面
  5. 调试您的应用程序,直到出现异常。

关于如何设置 xDebug 的说明在 http://xdebug.org/

Ubuntu 中你可以运行:

sudo apt-get install php5-xdebug

关于php - symfony2 phpunit : how to get exception message when status code is not expected one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29654008/

有关php - symfony2 phpunit : how to get exception message when status code is not expected one的更多相关文章

随机推荐