shortUrlService = $this->createMock(ShortUrlServiceInterface::class); $this->action = new EditShortUrlAction($this->shortUrlService, new ShortUrlDataTransformer( new ShortUrlStringifier([]), )); } #[Test] public function invalidDataThrowsError(): void { $request = (new ServerRequest())->withParsedBody([ 'maxVisits' => 'invalid', ]); $this->shortUrlService->expects($this->never())->method('updateShortUrl'); $this->expectException(ValidationException::class); $this->action->handle($request); } #[Test] public function correctShortCodeReturnsSuccess(): void { $request = (new ServerRequest())->withAttribute('shortCode', 'abc123') ->withAttribute(ApiKey::class, ApiKey::create()) ->withParsedBody([ 'maxVisits' => 5, ]); $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn(ShortUrl::createFake()); $resp = $this->action->handle($request); self::assertEquals(200, $resp->getStatusCode()); } }