deleter = $this->createMock(ShortUrlVisitsDeleterInterface::class); $this->action = new DeleteShortUrlVisitsAction($this->deleter); } #[Test, DataProvider('provideVisitsCounts')] public function visitsAreDeletedForShortUrl(int $visitsCount): void { $apiKey = ApiKey::create(); $request = ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey) ->withAttribute('shortCode', 'foo'); $this->deleter->expects($this->once())->method('deleteShortUrlVisits')->with( ShortUrlIdentifier::fromShortCodeAndDomain('foo'), $apiKey, )->willReturn(new BulkDeleteResult($visitsCount)); /** @var JsonResponse $resp */ $resp = $this->action->handle($request); $payload = $resp->getPayload(); self::assertEquals(['deletedVisits' => $visitsCount], $payload); } public static function provideVisitsCounts(): iterable { yield '1' => [1]; yield '0' => [0]; yield '300' => [300]; yield '1234' => [1234]; } }