Testing a Controller in Laravel I get the following error:
在Laravel中测试Controller我收到以下错误:
ErrorException: Undefined property: PostsControllerTest::$client
This is what my test looks like:
这是我的测试看起来像:
<?php
class PostsControllerTest extends TestCase {
public function testIndex()
{
$this->client->request('GET', 'posts');
}
}
It makes a get request to the /posts URI and I expect to get a NotFoundHttpException
它向/ posts URI发出get请求,我希望得到一个NotFoundHttpException
And not an undefined property error exception. Any advice?
而不是未定义的属性错误异常。任何建议?
1 个解决方案
#1
0
Seems like:
$this->client->request('GET', '/');
calls the Symfony\Component\DomCraw
调用Symfony \ Component \ DomCraw
and
$this->call('GET', '/');
calls the Illuminate\Http\Response
调用Illuminate \ Http \ Response
So, just using call instead of client->request, resolved the issue.
因此,只使用call而不是client-> request,解决了问题。
#1
0
Seems like:
$this->client->request('GET', '/');
calls the Symfony\Component\DomCraw
调用Symfony \ Component \ DomCraw
and
$this->call('GET', '/');
calls the Illuminate\Http\Response
调用Illuminate \ Http \ Response
So, just using call instead of client->request, resolved the issue.
因此,只使用call而不是client-> request,解决了问题。