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]); } }