/** * Reset a user's password * * @param string $email * @param string $password * @param string $code * @return User; */ public function reset($email, $password, $code) { if ($this->validate($email)) { try { $user = $this->service->reset($email, $password, $code); /* Dispatch Domain Events */ return $user; } catch (InvalidValueException $e) { $this->errors()->add('code', $e->getMessage()); } } }
/** @test */ public function should_reset_password_and_return_user() { $reminder = new Reminder($this->fixture['id'], $this->fixture['email'], $this->fixture['code']); $this->reminders->shouldReceive('findReminderByEmailAndCode')->andReturn($reminder); $this->users->shouldReceive('userOfEmail')->andReturn($this->user); $this->hasher->shouldReceive('hash')->andReturn(new HashedPassword('qwerty123')); $this->users->shouldReceive('update'); $this->reminders->shouldReceive('deleteReminderByCode'); $user = $this->service->reset('*****@*****.**', 'qwerty123', 'abc123'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user); }