visitsHelper = $this->createMock(VisitsStatsHelperInterface::class); $this->action = new OrphanVisitsAction($this->visitsHelper); } #[Test] public function requestIsHandled(): void { $visitor = Visitor::emptyInstance(); $visits = [Visit::forInvalidShortUrl($visitor), Visit::forRegularNotFound($visitor)]; $this->visitsHelper->expects($this->once())->method('orphanVisits')->with( $this->isInstanceOf(OrphanVisitsParams::class), )->willReturn(new Paginator(new ArrayAdapter($visits))); $visitsAmount = count($visits); /** @var JsonResponse $response */ $response = $this->action->handle( ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, ApiKey::create()), ); $payload = $response->getPayload(); self::assertCount($visitsAmount, $payload['visits']['data']); self::assertEquals(200, $response->getStatusCode()); } #[Test] public function exceptionIsThrownIfInvalidDataIsProvided(): void { $this->expectException(ValidationException::class); $this->action->handle( ServerRequestFactory::fromGlobals() ->withAttribute(ApiKey::class, ApiKey::create()) ->withQueryParams(['type' => 'invalidType']), ); } }