Used ShorturlIdentifier model whenever possible

This commit is contained in:
Alejandro Celaya
2021-05-23 08:41:42 +02:00
parent cd19876419
commit 5e6d2881bc
11 changed files with 112 additions and 80 deletions

View File

@@ -210,12 +210,16 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->flush();
self::assertNotNull($this->repo->findOne('my-cool-slug'));
self::assertNull($this->repo->findOne('my-cool-slug', 'doma.in'));
self::assertNull($this->repo->findOne('slug-not-in-use'));
self::assertNull($this->repo->findOne('another-slug'));
self::assertNull($this->repo->findOne('another-slug', 'example.com'));
self::assertNotNull($this->repo->findOne('another-slug', 'doma.in'));
self::assertNotNull($this->repo->findOne(ShortUrlIdentifier::fromShortCodeAndDomain('my-cool-slug')));
self::assertNull($this->repo->findOne(ShortUrlIdentifier::fromShortCodeAndDomain('my-cool-slug', 'doma.in')));
self::assertNull($this->repo->findOne(ShortUrlIdentifier::fromShortCodeAndDomain('slug-not-in-use')));
self::assertNull($this->repo->findOne(ShortUrlIdentifier::fromShortCodeAndDomain('another-slug')));
self::assertNull($this->repo->findOne(
ShortUrlIdentifier::fromShortCodeAndDomain('another-slug', 'example.com'),
));
self::assertNotNull($this->repo->findOne(
ShortUrlIdentifier::fromShortCodeAndDomain('another-slug', 'doma.in'),
));
}
/** @test */

View File

@@ -11,6 +11,7 @@ use Shlinkio\Shlink\Core\Entity\Domain;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Entity\VisitLocation;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Repository\VisitRepository;
@@ -89,32 +90,46 @@ class VisitRepositoryTest extends DatabaseTestCase
{
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
self::assertCount(0, $this->repo->findVisitsByShortCode('invalid', null, new VisitsListFiltering()));
self::assertCount(6, $this->repo->findVisitsByShortCode($shortCode, null, new VisitsListFiltering()));
self::assertCount(4, $this->repo->findVisitsByShortCode($shortCode, null, new VisitsListFiltering(null, true)));
self::assertCount(3, $this->repo->findVisitsByShortCode($shortCode, $domain, new VisitsListFiltering()));
self::assertCount(2, $this->repo->findVisitsByShortCode($shortCode, null, new VisitsListFiltering(
DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')),
)));
self::assertCount(4, $this->repo->findVisitsByShortCode($shortCode, null, new VisitsListFiltering(
DateRange::withStartDate(Chronos::parse('2016-01-03')),
)));
self::assertCount(1, $this->repo->findVisitsByShortCode($shortCode, $domain, new VisitsListFiltering(
DateRange::withStartDate(Chronos::parse('2016-01-03')),
)));
self::assertCount(0, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain('invalid'),
new VisitsListFiltering(),
));
self::assertCount(6, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(),
));
self::assertCount(4, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(null, true),
));
self::assertCount(3, $this->repo->findVisitsByShortCode(
$shortCode,
null,
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain),
new VisitsListFiltering(),
));
self::assertCount(2, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(
DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')),
),
));
self::assertCount(4, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))),
));
self::assertCount(1, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain),
new VisitsListFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))),
));
self::assertCount(3, $this->repo->findVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(null, false, null, 3, 2),
));
self::assertCount(2, $this->repo->findVisitsByShortCode(
$shortCode,
null,
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsListFiltering(null, false, null, 5, 4),
));
self::assertCount(1, $this->repo->findVisitsByShortCode(
$shortCode,
$domain,
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain),
new VisitsListFiltering(null, false, null, 3, 2),
));
}
@@ -124,22 +139,36 @@ class VisitRepositoryTest extends DatabaseTestCase
{
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
self::assertEquals(0, $this->repo->countVisitsByShortCode('invalid', null, new VisitsCountFiltering()));
self::assertEquals(6, $this->repo->countVisitsByShortCode($shortCode, null, new VisitsCountFiltering()));
self::assertEquals(4, $this->repo->countVisitsByShortCode($shortCode, null, new VisitsCountFiltering(
null,
true,
)));
self::assertEquals(3, $this->repo->countVisitsByShortCode($shortCode, $domain, new VisitsCountFiltering()));
self::assertEquals(2, $this->repo->countVisitsByShortCode($shortCode, null, new VisitsCountFiltering(
DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')),
)));
self::assertEquals(4, $this->repo->countVisitsByShortCode($shortCode, null, new VisitsCountFiltering(
DateRange::withStartDate(Chronos::parse('2016-01-03')),
)));
self::assertEquals(1, $this->repo->countVisitsByShortCode($shortCode, $domain, new VisitsCountFiltering(
DateRange::withStartDate(Chronos::parse('2016-01-03')),
)));
self::assertEquals(0, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain('invalid'),
new VisitsCountFiltering(),
));
self::assertEquals(6, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsCountFiltering(),
));
self::assertEquals(4, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsCountFiltering(null, true),
));
self::assertEquals(3, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain),
new VisitsCountFiltering(),
));
self::assertEquals(2, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsCountFiltering(
DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')),
),
));
self::assertEquals(4, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
new VisitsCountFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))),
));
self::assertEquals(1, $this->repo->countVisitsByShortCode(
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain),
new VisitsCountFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))),
));
}
/** @test */