/** * Load the User fixtures * * @param ObjectManager $manager * @return void */ public function load(ObjectManager $manager) { // Create valid Reminder $id = ReminderId::generate(); $email = new Email('*****@*****.**'); $code = ReminderCode::fromNative('code+99'); $reminder = new Reminder($id, $email, $code); $manager->persist($reminder); // Create expired Reminder Carbon::setTestNow(Carbon::create(2014, 10, 11, 10, 23, 34)); $id = ReminderId::generate(); $email = new Email('*****@*****.**'); $code = ReminderCode::fromNative('code+1'); $reminder = new Reminder($id, $email, $code); Carbon::setTestNow(); $manager->persist($reminder); $manager->flush(); }
/** * Reset a user's password * * @param string $email * @param string $password * @param string $code * @return User; */ public function reset($email, $password, $code) { if ($this->check($email, $code)) { $user = $this->findUserByEmail(Email::fromNative($email)); $password = $this->hasher->hash(new Password($password)); $user->resetPassword($password); $this->users->update($user); $this->reminders->deleteReminderByCode(ReminderCode::fromNative($code)); return $user; } throw new InvalidValueException("{$code} is not a valid reminder code"); }
/** @test */ public function should_return_as_string() { $code = ReminderCode::fromNative('D1zcA5ncaEHzmjvCGjJIt3Kd8sGxTTtE7DkathqB'); $this->assertEquals('D1zcA5ncaEHzmjvCGjJIt3Kd8sGxTTtE7DkathqB', $code->toString()); $this->assertEquals('D1zcA5ncaEHzmjvCGjJIt3Kd8sGxTTtE7DkathqB', (string) $code); }
/** * Get the Reminder code * * @return string */ public function code() { return ReminderCode::fromNative($this->code); }
/** @test */ public function should_delete_expired_reminders() { $this->executor->execute($this->loader->getFixtures()); $code = ReminderCode::fromNative('code+1'); $email = new Email('*****@*****.**'); $this->repository->deleteExpiredReminders(); $reminder = $this->repository->findReminderByEmailAndCode($email, $code); $this->assertEquals(null, $reminder); }