我正在使用phpunit和mockery学习laravel中的单元测试.我目前正在尝试测试UsersController :: store().
我正在嘲笑用户模型并使用它来测试索引方法,这似乎有效.当我取出$ this-> user-> all()时,测试失败,当它进入时.
在测试store方法时,我使用mock来测试用户模型是否接收到validate()一次.store方法为空,但测试通过.为了简单起见,我遗漏了班级中不相关的部分
<?php
class UsersController extends BaseController {
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$users = $this->user->all();
return View::make('users.index')
->with('users', $users);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return View::make('users.create');
}
/**
* Store a newly created resource in storage.
* …Run Code Online (Sandbox Code Playgroud)