diff --git a/module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php b/module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php index 097c8875..5442af7c 100644 --- a/module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php +++ b/module/Core/src/ShortUrl/ShortUrlVisitsDeleter.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl; +use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Model\BulkDeleteResult; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Visit\Repository\VisitDeleterRepositoryInterface; @@ -17,6 +18,9 @@ class ShortUrlVisitsDeleter implements ShortUrlVisitsDeleterInterface ) { } + /** + * @throws ShortUrlNotFoundException + */ public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult { $this->resolver->resolveShortUrl($identifier, $apiKey); diff --git a/module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php b/module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php index dc29ef94..b0ac0e6a 100644 --- a/module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php +++ b/module/Core/src/ShortUrl/ShortUrlVisitsDeleterInterface.php @@ -4,11 +4,15 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl; +use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Model\BulkDeleteResult; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Rest\Entity\ApiKey; interface ShortUrlVisitsDeleterInterface { + /** + * @throws ShortUrlNotFoundException + */ public function deleteShortUrlVisits(ShortUrlIdentifier $identifier, ?ApiKey $apiKey): BulkDeleteResult; } diff --git a/module/Core/test/ShortUrl/ShortUrlVisitsDeleterTest.php b/module/Core/test/ShortUrl/ShortUrlVisitsDeleterTest.php new file mode 100644 index 00000000..461fc78b --- /dev/null +++ b/module/Core/test/ShortUrl/ShortUrlVisitsDeleterTest.php @@ -0,0 +1,51 @@ +repository = $this->createMock(VisitDeleterRepositoryInterface::class); + $this->resolver = $this->createMock(ShortUrlResolverInterface::class); + + $this->deleter = new ShortUrlVisitsDeleter($this->repository, $this->resolver); + } + + #[Test, DataProvider('provideVisitsCounts')] + public function returnsDeletedVisitsFromRepo(int $visitsCount): void + { + $identifier = ShortUrlIdentifier::fromShortCodeAndDomain(''); + + $this->resolver->expects($this->once())->method('resolveShortUrl')->with($identifier, null); + $this->repository->expects($this->once())->method('deleteShortUrlVisits')->with($identifier, null)->willReturn( + $visitsCount, + ); + + $result = $this->deleter->deleteShortUrlVisits($identifier, null); + + self::assertEquals($visitsCount, $result->affectedItems); + } + + public static function provideVisitsCounts(): iterable + { + yield '45' => [45]; + yield '5000' => [5000]; + yield '0' => [0]; + } +}