Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用会话测试应用程序_Php_Laravel - Fatal编程技术网

Php 使用会话测试应用程序

Php 使用会话测试应用程序,php,laravel,Php,Laravel,我正在用即将推出的Laravel 4框架构建一个应用程序。我想为它编写单元测试。该应用程序使用会话。因此,我必须重新创建用户状态以正确测试所有内容 以下是我想做的事情: User::login($user); // updates the session $crawler = $this->client->request('GET', 'http://myapp.dev/'); $this->assertTrue($this->client->getResponse

我正在用即将推出的Laravel 4框架构建一个应用程序。我想为它编写单元测试。该应用程序使用会话。因此,我必须重新创建用户状态以正确测试所有内容

以下是我想做的事情:

User::login($user); // updates the session
$crawler = $this->client->request('GET', 'http://myapp.dev/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter("#logout-button"));
但是,
$this->client->request
会创建一个新请求,这样会话就不会被传播

该会话在测试中可用。但是,当您使用$this->client->request('GET','something')时,该请求的会话不再存在,因为它使用数组驱动程序。我可以尝试使用文件驱动程序,但是如何向请求发送自定义会话id呢


我如何解决这个问题?我可以通过假cookie传递会话id吗?或者以某种方式传递会话对象?

使用
$this->be($user)
而不是
Auth::login
。请参见此处的早期L4文档:

我没有使用Auth软件包。如果我想要的不是Auth包中包含的内容,那该怎么办呢?
$this->be
还有第二个参数指定要使用哪个Auth驱动程序。同样,我没有使用Auth包。完全我想在我的测试环境中进行常规会话访问,然后尝试
$this->app['session']
查看组件是否已绑定,但我不确定。$this->app['session']已绑定,但会话似乎未自动启动。我不太清楚发生了什么事。