visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class); $this->action = new ShortUrlVisitsAction($this->visitsHelper->reveal()); } /** @test */ public function providingCorrectShortCodeReturnsVisits(): void { $shortCode = 'abc123'; $this->visitsHelper->visitsForShortUrl( new ShortUrlIdentifier($shortCode), Argument::type(VisitsParams::class), Argument::type(ApiKey::class), )->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); $response = $this->action->handle($this->requestWithApiKey()->withAttribute('shortCode', $shortCode)); self::assertEquals(200, $response->getStatusCode()); } /** @test */ public function paramsAreReadFromQuery(): void { $shortCode = 'abc123'; $this->visitsHelper->visitsForShortUrl(new ShortUrlIdentifier($shortCode), new VisitsParams( DateRange::withEndDate(Chronos::parse('2016-01-01 00:00:00')), 3, 10, ), Argument::type(ApiKey::class)) ->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); $response = $this->action->handle( $this->requestWithApiKey()->withAttribute('shortCode', $shortCode) ->withQueryParams([ 'endDate' => '2016-01-01 00:00:00', 'page' => '3', 'itemsPerPage' => '10', ]), ); self::assertEquals(200, $response->getStatusCode()); } private function requestWithApiKey(): ServerRequestInterface { return ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, ApiKey::create()); } }