request = Request::create('http://localhost/'); $stack = self::getContainer()->get(RequestStack::class); self::assertInstanceOf(RequestStack::class, $stack); $stack->push($this->request); } private function getLoginLinkHandler(): LoginLinkHandlerInterface { /** @var LoginLinkHandlerInterface $handler */ $handler = self::getContainer()->get(LoginLinkHandlerInterface::class); return $handler; } public function testLoginLinkIsValidBeforePasswordChange(): void { $user = $this->getUserByRole(User::ROLE_USER); $handler = $this->getLoginLinkHandler(); $link = $handler->createLoginLink($user, $this->request); $consumed = $handler->consumeLoginLink(Request::create($link->getUrl())); self::assertSame($user->getUserIdentifier(), $consumed->getUserIdentifier()); } public function testLoginLinkIsRejectedAfterPasswordChange(): void { $user = $this->getUserByRole(User::ROLE_USER); $handler = $this->getLoginLinkHandler(); $link = $handler->createLoginLink($user, $this->request); // simulate the user completing the password reset wizard: the password // hash changes, which must invalidate the signature of the old link $user->setPassword('$2y$13$changedchangedchangedchangedchangedchangedchangedchangedchg'); $this->getEntityManager()->flush(); $this->expectException(InvalidLoginLinkException::class); $handler->consumeLoginLink(Request::create($link->getUrl())); } }