Laravel5.1 写测试用例时如何获取跳转后的正文内容
$content=$this->get('/guest/register?game=1',['pos'=>0])->followRedirects()->seeJson([
'status'=>'success'
])->response->getContent();
$rs=json_decode($content,true);
此时content内容为空,但是会在console中打印出跳转后的json输出。
样例输出:
PHPUnit 4.8.16 by Sebastian Bergmann and contributors.
F{"status":"success","uid":"318480477","username":"dmzw-318480477","usertoken":"xmTSTGlSKFJpYFqpNG58EvlTDa6VdZaT"}
Time: 927 ms, Memory: 18.75Mb
There was 1 failure:
1) GuestTest::testGuestregister
Invalid JSON was returned from the route. Perhaps an exception was thrown?
/var/www/laravel/mapi_2144_cn/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:248
/var/www/laravel/mapi_2144_cn/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:220
/var/www/laravel/mapi_2144_cn/tests/GuestTest.php:15
FAILURES!
Tests: 1, Assertions: 4, Failures: 1.
可以直接用
$this->fail("11111111111111")
输出内容