urlShortener = $this->createMock(UrlShortenerInterface::class); $transformer = $this->createMock(DataTransformerInterface::class); $transformer->method('transform')->willReturn([]); $this->action = new SingleStepCreateShortUrlAction( $this->urlShortener, $transformer, new UrlShortenerOptions(), ); } #[Test] public function properDataIsPassedWhenGeneratingShortCode(): void { $apiKey = ApiKey::create(); $request = (new ServerRequest())->withQueryParams([ 'longUrl' => 'http://foobar.com', ])->withAttribute(ApiKey::class, $apiKey); $this->urlShortener->expects($this->once())->method('shorten')->with( ShortUrlCreation::fromRawData(['apiKey' => $apiKey, 'longUrl' => 'http://foobar.com']), )->willReturn(UrlShorteningResult::withoutErrorOnEventDispatching(ShortUrl::createFake())); $resp = $this->action->handle($request); self::assertEquals(200, $resp->getStatusCode()); } }