Laravel 4.1 PHPUnit测试:在非对象上使用()调用成员函数
您好,我正在尝试编写PHPUnit测试来测试我的登录控制器,我的代码在浏览器中似乎运行良好,但是当我运行php单元测试时,我得到以下错误 错误: 方法: 单元测试:Laravel 4.1 PHPUnit测试:在非对象上使用()调用成员函数,php,unit-testing,laravel-4,phpunit,mockery,Php,Unit Testing,Laravel 4,Phpunit,Mockery,您好,我正在尝试编写PHPUnit测试来测试我的登录控制器,我的代码在浏览器中似乎运行良好,但是当我运行php单元测试时,我得到以下错误 错误: 方法: 单元测试: 说到使用mockry,我有点笨,所以我想问题可能在于我如何模拟重定向对象?您需要从Redirect::shouldReceive返回一些内容 public function testStore() { Auth::shouldReceive('attempt') ->once() -&g
说到使用mockry,我有点笨,所以我想问题可能在于我如何模拟重定向对象?您需要从Redirect::shouldReceive返回一些内容
public function testStore()
{
Auth::shouldReceive('attempt')
->once()
->andReturn(true);
Redirect::shouldReceive('intended')
->once()
->andReturn($redirectResponse = Mockery::mock('Illuminate\Http\RedirectResponse'));
$this->call('POST', 'session');
}
重定向正在正确地接收预期结果,但根据实际函数,它会返回一些特定的内容,即Lightlight\Http\RedirectResponse的实例
您可以查看Illumb\Routing\Redirector了解更多信息
public function store()
{
$input = Input::only('email', 'password');
$attempt = Auth::attempt($input);
if($attempt){
return Redirect::intended('/')
->with('flash_message', Lang::get('sessions.you_have_logged_in'));
}
}
public function testStore()
{
Auth::shouldReceive('attempt')
->once()
->andReturn(true);
Redirect::shouldReceive('intended')
->once();
$this->call('POST', 'session');
}
public function testStore()
{
Auth::shouldReceive('attempt')
->once()
->andReturn(true);
Redirect::shouldReceive('intended')
->once()
->andReturn($redirectResponse = Mockery::mock('Illuminate\Http\RedirectResponse'));
$this->call('POST', 'session');
}