phpunit避免截断输出

时间:2017-08-09 15:10:17

标签: console phpunit

如何避免phpunit测试输出被截断:

1) Tests\ApiTest::testGetMetricList
GuzzleHttp\Exception\ServerException: Server error: `GET http://localhost/micobe/myproject_p4/index.php/investors/get_metric_list` resulted in a `500 Internal Server Error` response:
<br />
    <font size='1'><table class='xdebug-error xe-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr (truncated...)


    /var/www/html/landing-myproject-page/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/guzzle/src/Middleware.php:65
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:203
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:156
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/TaskQueue.php:47
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:246
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:223
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:267
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:225
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/promises/src/Promise.php:62
    /var/www/html/landing-myproject-page/vendor/guzzlehttp/guzzle/src/Client.php:131
    /var/www/html/landing-myproject-page/app/Http/Controllers/ApiController.php:171
    /var/www/html/landing-myproject-page/tests/ApiTest.php:31

2 个答案:

答案 0 :(得分:1)

如果您遇到了通过PhpUnit调试(被截断...)错误消息的艰巨任务,请参见以下全局解决方案!

捕获的异常与枪口版本

有关
  

在您的phpunit测试中进行try-catch会得到GuzzleException $ e

示例

$ client = new GuzzleHttp \ Client(['base_uri'=>'https://foo.com/api/']);

try {

    $response = $client->request('GET','/v1/testYourEndpoint');

} catch (\GuzzleHttp\Exception\ClientErrorResponseException  $e) {

    var_dump($e->getResponse()->getBody()->getContents());

} catch (\GuzzleHttp\Exception\RequestException $e) {

       print_r($e->xdebug_message);
       var_dump($e->getResponse()->getBody()->getContents());

} catch (\GuzzleHttp\Exception\ClientException  $e) {

    var_dump($e->getResponse()->getBody()->getContents());

}

答案 1 :(得分:0)

Guzzle截断了输出,而不是PHPUnit。如果您使用的是Laravel,则可以使用dd($response->getBody());获取完整输出。