Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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
Laravel 4.1 PHPUnit测试:在非对象上使用()调用成员函数_Php_Unit Testing_Laravel 4_Phpunit_Mockery - Fatal编程技术网

Laravel 4.1 PHPUnit测试:在非对象上使用()调用成员函数

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

您好,我正在尝试编写PHPUnit测试来测试我的登录控制器,我的代码在浏览器中似乎运行良好,但是当我运行php单元测试时,我得到以下错误

错误:

方法:

单元测试:


说到使用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');
}