. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\ResetHandlers; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Http\RequestHandlers\PasswordResetPage; use Fisharebest\Webtrees\Services\UserService; use Fisharebest\Webtrees\TestCase; use Fisharebest\Webtrees\User; /** * @covers \Fisharebest\Webtrees\Http\RequestHandlers\PasswordResetPage */ class PasswordResetPageTest extends TestCase { /** * @return void */ public function testPasswordResetPageWithValidToken(): void { $user = $this->createMock(User::class); $user_service = $this->createMock(UserService::class); $user_service ->expects($this->once()) ->method('findByToken') ->with('1234') ->willReturn($user); $request = self::createRequest() ->withAttribute('token', '1234'); $handler = new PasswordResetPage($user_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); } /** * @return void */ public function testPasswordResetPageWithoutValidToken(): void { $user_service = $this->createMock(UserService::class); $user_service ->expects($this->once()) ->method('findByToken') ->with('4321') ->willReturn(null); $request = self::createRequest() ->withAttribute('token', '4321'); $handler = new PasswordResetPage($user_service); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); } }