I'm working with PhpSpec and for some reason when I mock my dependencies and call them the willReturn
method of PhpSpec give me a null
value instead of the value passed.
This is the method that I'm trying to describe
/**
* 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;
}
My Spec
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);
}
}
I'm stuck with this issue, any suggest will be appreciated.