createServerRequest('POST', '/login') ->withParsedBody([ 'username' => ' alice ', 'password' => ' secret ', ]); $payload = LoginRequest::fromRequest($request); self::assertSame('alice', $payload->username); self::assertSame(' secret ', $payload->password); } public function testChangePasswordRequestPreservesPasswordWhitespace(): void { $request = (new ServerRequestFactory()) ->createServerRequest('POST', '/account/password') ->withParsedBody([ 'current_password' => ' current ', 'new_password' => ' nextpass ', 'new_password_confirm' => ' nextpass ', ]); $payload = ChangePasswordRequest::fromRequest($request); self::assertSame(' current ', $payload->currentPassword); self::assertSame(' nextpass ', $payload->newPassword); self::assertSame(' nextpass ', $payload->newPasswordConfirm); } public function testResetPasswordRequestPreservesPasswordWhitespace(): void { $request = (new ServerRequestFactory()) ->createServerRequest('POST', '/password/reset') ->withParsedBody([ 'token' => ' token ', 'new_password' => ' nextpass ', 'new_password_confirm' => ' nextpass ', ]); $payload = ResetPasswordRequest::fromRequest($request); self::assertSame('token', $payload->token); self::assertSame(' nextpass ', $payload->newPassword); self::assertSame(' nextpass ', $payload->newPasswordConfirm); } public function testCreateUserRequestPreservesPasswordWhitespace(): void { $request = (new ServerRequestFactory()) ->createServerRequest('POST', '/admin/users') ->withParsedBody([ 'username' => ' Alice ', 'email' => ' alice@example.com ', 'password' => ' secret123 ', 'password_confirm' => ' secret123 ', 'role' => 'editor', ]); $payload = CreateUserRequest::fromRequest($request, ['user', 'editor']); self::assertSame('Alice', $payload->username); self::assertSame('alice@example.com', $payload->email); self::assertSame(' secret123 ', $payload->password); self::assertSame(' secret123 ', $payload->passwordConfirm); self::assertSame('editor', $payload->role); } }