helper = $this->createMock(VisitsStatsHelperInterface::class); $this->action = new GlobalVisitsAction($this->helper); } /** @test */ public function statsAreReturnedFromHelper(): void { $apiKey = ApiKey::create(); $stats = new VisitsStats(5, 3); $this->helper->expects($this->once())->method('getVisitsStats')->with($apiKey)->willReturn($stats); /** @var JsonResponse $resp */ $resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey)); $payload = $resp->getPayload(); self::assertEquals($payload, ['visits' => $stats]); } }