/** * Register a new user * * @param string $email * @param string $username * @param string $password * @return User */ public function register($email, $username, $password) { if ($this->validate(compact('email', 'username'))) { $user = $this->service->register($email, $username, $password); /* Dispatch Domain Events */ return $user; } }
/** @test */ public function should_register_new_user() { $this->repository->shouldReceive('userOfEmail')->andReturn(null); $this->repository->shouldReceive('userOfUsername')->andReturn(null); $this->repository->shouldReceive('nextIdentity')->andReturn(UserId::generate()); $this->hashing->shouldReceive('hash')->andReturn(new HashedPassword('password')); $this->repository->shouldReceive('add'); $user = $this->registerUserService->register('*****@*****.**', 'username', 'password'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user); }