【发布时间】:2014-08-23 16:18:33
【问题描述】:
我正在使用 PhpSpec,由于某种原因,当我模拟我的依赖项并调用它们时,PhpSpec 的 willReturn 方法给我一个 null 值而不是传递的值。
这就是我要描述的方法
/**
* Register an User
*
* @param array $infoUser
* @return User
*/
public function register(array $infoUser)
{
$user = $this->user->create($infoUser);
$this->raise(new UserRegistered($user));
return $user;
}
我的规格
class BaseAuthSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Core\Auth\BaseAuth');
}
function let(AuthManager $guard,UserAuthRepository $user)
{
$this->beConstructedWith($guard,$user);
}
function it_register_an_user(UserAuthRepository $useRepo)
{
$user = [
'username' => 'fabri',
'email' => 'test@test.com',
'password' => 'password',
'repeat_password' => 'password'
];
$userModel = new User($user);
// this line return null instead the $userModel
$useRepo->create($user)->shouldBeCalled()->willReturn($userModel);
$this->raise(new UserRegistered($userModel))->shouldReturn(null);
$this->register($user)->shouldReturn($userModel);
}
}
我被这个问题困住了,任何建议都将不胜感激。
【问题讨论】: