4
我有在Laravel 4Laravel 4測試環節
測試控制器一個問題,我有下面的代碼:
public function getRemind()
{
$status = \Session::get('status');
$error = \Session::get('error');
$email = \Session::get('email');
return \View::make('admin/reminds/remind_form', compact('status', 'error', 'email'));
}
我要測試是否在視圖中由控制器傳遞正確的數據:
public function testGetRemind()
{
\Session::set('status', 'status');
\Session::set('error', 'error');
\Session::set('email', 'email');
$response = $this->action('GET', 'Admin\[email protected]');
$this->assertTrue($response->isOk(), 'Get remind action is not ok');
$this->assertViewHas('status', 'status');
$this->assertViewHas('error', 'error');
$this->assertViewHas('email', 'email');
}
但是這不起作用。
另外我不能模擬會話類,因爲它不被框架允許 - 當我嘗試這樣做時會出現很多錯誤。