mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Create ShortUrlVisitsDeleterTest
This commit is contained in:
parent
ffc0555c7c
commit
69ff7de481
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
51
module/Core/test/ShortUrl/ShortUrlVisitsDeleterTest.php
Normal file
51
module/Core/test/ShortUrl/ShortUrlVisitsDeleterTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\ShortUrl;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlVisitsDeleter;
|
||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitDeleterRepositoryInterface;
|
||||
|
||||
class ShortUrlVisitsDeleterTest extends TestCase
|
||||
{
|
||||
private ShortUrlVisitsDeleter $deleter;
|
||||
private MockObject & VisitDeleterRepositoryInterface $repository;
|
||||
private MockObject & ShortUrlResolverInterface $resolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->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];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user