mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 12:13:13 +08:00
Update to doctrine ORM 3.0
This commit is contained in:
@@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
||||
use Shlinkio\Shlink\Core\Domain\DomainService;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
||||
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
|
||||
@@ -34,7 +34,7 @@ class DomainServiceTest extends TestCase
|
||||
#[Test, DataProvider('provideExcludedDomains')]
|
||||
public function listDomainsDelegatesIntoRepository(array $domains, array $expectedResult, ?ApiKey $apiKey): void
|
||||
{
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->expects($this->once())->method('findDomains')->with($apiKey)->willReturn($domains);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
|
||||
@@ -126,7 +126,7 @@ class DomainServiceTest extends TestCase
|
||||
public function getOrCreateAlwaysPersistsDomain(?Domain $foundDomain, ?ApiKey $apiKey): void
|
||||
{
|
||||
$authority = 'example.com';
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(
|
||||
$foundDomain,
|
||||
);
|
||||
@@ -148,7 +148,7 @@ class DomainServiceTest extends TestCase
|
||||
$domain = Domain::withAuthority($authority);
|
||||
$domain->setId('1');
|
||||
$apiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)));
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(null);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
$this->em->expects($this->never())->method('persist');
|
||||
@@ -163,7 +163,7 @@ class DomainServiceTest extends TestCase
|
||||
public function configureNotFoundRedirectsConfiguresFetchedDomain(?Domain $foundDomain, ?ApiKey $apiKey): void
|
||||
{
|
||||
$authority = 'example.com';
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn($foundDomain);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
$this->em->expects($this->once())->method('persist')->with($foundDomain ?? $this->isInstanceOf(Domain::class));
|
||||
|
||||
@@ -16,12 +16,12 @@ use RuntimeException;
|
||||
use Shlinkio\Shlink\Core\Importer\ImportedLinksProcessor;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortCodeUniquenessHelperInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver;
|
||||
use Shlinkio\Shlink\Core\Util\DoctrineBatchHelperInterface;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepository;
|
||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkOrphanVisit;
|
||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkVisit;
|
||||
@@ -42,13 +42,13 @@ class ImportedLinksProcessorTest extends TestCase
|
||||
private ImportedLinksProcessor $processor;
|
||||
private MockObject & EntityManagerInterface $em;
|
||||
private MockObject & ShortCodeUniquenessHelperInterface $shortCodeHelper;
|
||||
private MockObject & ShortUrlRepositoryInterface $repo;
|
||||
private MockObject & ShortUrlRepository $repo;
|
||||
private MockObject & StyleInterface $io;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->em = $this->createMock(EntityManagerInterface::class);
|
||||
$this->repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$this->repo = $this->createMock(ShortUrlRepository::class);
|
||||
|
||||
$this->shortCodeHelper = $this->createMock(ShortCodeUniquenessHelperInterface::class);
|
||||
$batchHelper = $this->createMock(DoctrineBatchHelperInterface::class);
|
||||
@@ -281,7 +281,7 @@ class ImportedLinksProcessorTest extends TestCase
|
||||
sprintf('<info>Imported %s</info> orphan visits.', $expectedImportedVisits),
|
||||
);
|
||||
|
||||
$visitRepo = $this->createMock(VisitRepositoryInterface::class);
|
||||
$visitRepo = $this->createMock(VisitRepository::class);
|
||||
$visitRepo->expects($importOrphanVisits ? $this->once() : $this->never())->method(
|
||||
'findMostRecentOrphanVisit',
|
||||
)->willReturn($lastOrphanVisit);
|
||||
|
||||
@@ -11,11 +11,11 @@ use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
||||
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver;
|
||||
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Repository\TagRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
|
||||
|
||||
use function count;
|
||||
|
||||
@@ -50,7 +50,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
|
||||
#[Test, DataProvider('provideFoundDomains')]
|
||||
public function findsOrCreatesDomainWhenValueIsProvided(?Domain $foundDomain, string $authority): void
|
||||
{
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->expects($this->once())->method('findOneBy')->with(['authority' => $authority])->willReturn($foundDomain);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
|
||||
@@ -78,7 +78,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
|
||||
// One of the tags will already exist. The rest will be new
|
||||
$expectedPersistedTags = $expectedLookedOutTags - 1;
|
||||
|
||||
$tagRepo = $this->createMock(TagRepositoryInterface::class);
|
||||
$tagRepo = $this->createMock(TagRepository::class);
|
||||
$tagRepo->expects($this->exactly($expectedLookedOutTags))->method('findOneBy')->with(
|
||||
$this->isType('array'),
|
||||
)->willReturnCallback(function (array $criteria): ?Tag {
|
||||
@@ -116,7 +116,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
|
||||
#[Test]
|
||||
public function newDomainsAreMemoizedUntilStateIsCleared(): void
|
||||
{
|
||||
$repo = $this->createMock(DomainRepositoryInterface::class);
|
||||
$repo = $this->createMock(DomainRepository::class);
|
||||
$repo->expects($this->exactly(3))->method('findOneBy')->with($this->isType('array'))->willReturn(null);
|
||||
$this->em->method('getRepository')->with(Domain::class)->willReturn($repo);
|
||||
|
||||
@@ -135,7 +135,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
|
||||
#[Test]
|
||||
public function newTagsAreMemoizedUntilStateIsCleared(): void
|
||||
{
|
||||
$tagRepo = $this->createMock(TagRepositoryInterface::class);
|
||||
$tagRepo = $this->createMock(TagRepository::class);
|
||||
$tagRepo->expects($this->exactly(6))->method('findOneBy')->with($this->isType('array'))->willReturn(null);
|
||||
$this->em->method('getRepository')->with(Tag::class)->willReturn($tagRepo);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolver;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
||||
@@ -32,12 +32,12 @@ class ShortUrlResolverTest extends TestCase
|
||||
{
|
||||
private ShortUrlResolver $urlResolver;
|
||||
private MockObject & EntityManagerInterface $em;
|
||||
private MockObject & ShortUrlRepositoryInterface $repo;
|
||||
private MockObject & ShortUrlRepository $repo;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->em = $this->createMock(EntityManagerInterface::class);
|
||||
$this->repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$this->repo = $this->createMock(ShortUrlRepository::class);
|
||||
$this->urlResolver = new ShortUrlResolver($this->em, new UrlShortenerOptions());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
||||
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
@@ -90,7 +90,7 @@ class VisitsStatsHelperTest extends TestCase
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
$spec = $apiKey?->spec();
|
||||
|
||||
$repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->once())->method('shortCodeIsInUse')->with($identifier, $spec)->willReturn(true);
|
||||
|
||||
$list = array_map(
|
||||
@@ -123,7 +123,7 @@ class VisitsStatsHelperTest extends TestCase
|
||||
$shortCode = '123ABC';
|
||||
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
||||
|
||||
$repo = $this->createMock(ShortUrlRepositoryInterface::class);
|
||||
$repo = $this->createMock(ShortUrlRepository::class);
|
||||
$repo->expects($this->once())->method('shortCodeIsInUse')->with($identifier, null)->willReturn(false);
|
||||
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user