mirror of
https://github.com/shlinkio/shlink.git
synced 2026-08-11 05:24:46 -05:00
Migrate from PHPUnit annotations to native attributes
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ShlinkioDbTest\Shlink\Core\Domain\Repository;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
||||
@@ -26,7 +27,7 @@ class DomainRepositoryTest extends DatabaseTestCase
|
||||
$this->repo = $this->getEntityManager()->getRepository(Domain::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function expectedDomainsAreFoundWhenNoApiKeyIsInvolved(): void
|
||||
{
|
||||
$fooDomain = Domain::withAuthority('foo.com');
|
||||
@@ -61,7 +62,7 @@ class DomainRepositoryTest extends DatabaseTestCase
|
||||
self::assertTrue($this->repo->domainExists('detached.com'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function expectedDomainsAreFoundWhenApiKeyIsProvided(): void
|
||||
{
|
||||
$authorApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls()));
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\CrawlableShortCodesQuery;
|
||||
@@ -19,7 +20,7 @@ class CrawlableShortCodesQueryTest extends DatabaseTestCase
|
||||
$this->query = new CrawlableShortCodesQuery($em, $em->getClassMetadata(ShortUrl::class));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function invokingQueryReturnsExpectedResult(): void
|
||||
{
|
||||
$createShortUrl = fn (bool $crawlable) => ShortUrl::create(
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Model\Ordering;
|
||||
@@ -37,7 +38,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
$this->relationResolver = new PersistenceShortUrlRelationResolver($em);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countListReturnsProperNumberOfResults(): void
|
||||
{
|
||||
$count = 5;
|
||||
@@ -49,7 +50,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals($count, $this->repo->countList(new ShortUrlsCountFiltering()));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findListProperlyFiltersResult(): void
|
||||
{
|
||||
$foo = ShortUrl::create(
|
||||
@@ -143,7 +144,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findListProperlyMapsFieldNamesToColumnNamesWhenOrdering(): void
|
||||
{
|
||||
$urls = ['a', 'z', 'c', 'b'];
|
||||
@@ -164,7 +165,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals('z', $result[3]->getLongUrl());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findListReturnsOnlyThoseWithMatchingTags(): void
|
||||
{
|
||||
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||
@@ -273,7 +274,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findListReturnsOnlyThoseWithMatchingDomains(): void
|
||||
{
|
||||
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||
@@ -309,7 +310,7 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
self::assertCount(0, $this->repo->findList($buildFiltering('no results')));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findListReturnsOnlyThoseWithoutExcludedUrls(): void
|
||||
{
|
||||
$shortUrl1 = ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace ShlinkioDbTest\Shlink\Core\ShortUrl\Repository;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
||||
@@ -30,7 +31,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneWithDomainFallbackReturnsProperData(): void
|
||||
{
|
||||
$regularOne = ShortUrl::create(ShortUrlCreation::fromRawData(['customSlug' => 'Foo', 'longUrl' => 'foo']));
|
||||
@@ -97,7 +98,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function shortCodeIsInUseLooksForShortUrlInProperSetOfTables(): void
|
||||
{
|
||||
$shortUrlWithoutDomain = ShortUrl::create(
|
||||
@@ -126,7 +127,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneLooksForShortUrlInProperSetOfTables(): void
|
||||
{
|
||||
$shortUrlWithoutDomain = ShortUrl::create(
|
||||
@@ -153,7 +154,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneMatchingReturnsNullForNonExistingShortUrls(): void
|
||||
{
|
||||
self::assertNull($this->repo->findOneMatching(ShortUrlCreation::fromRawData(['longUrl' => 'foobar'])));
|
||||
@@ -168,7 +169,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
])));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneMatchingAppliesProperConditions(): void
|
||||
{
|
||||
$start = Chronos::parse('2020-03-05 20:18:30');
|
||||
@@ -237,7 +238,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneMatchingReturnsOldestOneWhenThereAreMultipleMatches(): void
|
||||
{
|
||||
$start = Chronos::parse('2020-03-05 20:18:30');
|
||||
@@ -265,7 +266,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
self::assertNotSame($shortUrl3, $result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOneMatchingAppliesProvidedApiKeyConditions(): void
|
||||
{
|
||||
$start = Chronos::parse('2020-03-05 20:18:30');
|
||||
@@ -391,7 +392,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function importedShortUrlsAreFoundWhenExpected(): void
|
||||
{
|
||||
$buildImported = static fn (string $shortCode, ?String $domain = null) =>
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioDbTest\Shlink\Core\Tag\Paginator\Adapter;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Model\TagsParams;
|
||||
use Shlinkio\Shlink\Core\Tag\Paginator\Adapter\TagsPaginatorAdapter;
|
||||
@@ -24,9 +26,8 @@ class TagsPaginatorAdapterTest extends DatabaseTestCase
|
||||
/**
|
||||
* @param int<0, max> $offset
|
||||
* @param int<0, max> $length
|
||||
* @test
|
||||
* @dataProvider provideFilters
|
||||
*/
|
||||
#[Test, DataProvider('provideFilters')]
|
||||
public function expectedListOfTagsIsReturned(
|
||||
?string $searchTerm,
|
||||
?string $orderBy,
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioDbTest\Shlink\Core\Tag\Repository;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Model\Ordering;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
@@ -34,13 +36,13 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function deleteByNameDoesNothingWhenEmptyListIsProvided(): void
|
||||
{
|
||||
self::assertEquals(0, $this->repo->deleteByName([]));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function allTagsWhichMatchNameAreDeleted(): void
|
||||
{
|
||||
$names = ['foo', 'bar', 'baz'];
|
||||
@@ -54,10 +56,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals(2, $this->repo->deleteByName($toDelete));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideFilters
|
||||
*/
|
||||
#[Test, DataProvider('provideFilters')]
|
||||
public function properTagsInfoIsReturned(?TagsListFiltering $filtering, array $expectedList): void
|
||||
{
|
||||
$names = ['foo', 'bar', 'baz', 'another'];
|
||||
@@ -221,7 +220,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
||||
]];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function tagExistsReturnsExpectedResultBasedOnApiKey(): void
|
||||
{
|
||||
$domain = Domain::withAuthority('foo.com');
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioDbTest\Shlink\Core\Visit\Repository;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
||||
@@ -25,10 +27,7 @@ class VisitLocationRepositoryTest extends DatabaseTestCase
|
||||
$this->repo = new VisitLocationRepository($em, $em->getClassMetadata(Visit::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideBlockSize
|
||||
*/
|
||||
#[Test, DataProvider('provideBlockSize')]
|
||||
public function findVisitsReturnsProperVisits(int $blockSize): void
|
||||
{
|
||||
$shortUrl = ShortUrl::createFake();
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace ShlinkioDbTest\Shlink\Core\Visit\Repository;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
@@ -40,7 +41,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
$this->relationResolver = new PersistenceShortUrlRelationResolver($this->getEntityManager());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findVisitsByShortCodeReturnsProperData(): void
|
||||
{
|
||||
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
|
||||
@@ -89,7 +90,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countVisitsByShortCodeReturnsProperData(): void
|
||||
{
|
||||
[$shortCode, $domain] = $this->createShortUrlsAndVisits();
|
||||
@@ -126,7 +127,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findVisitsByShortCodeReturnsProperDataWhenUsingAPiKeys(): void
|
||||
{
|
||||
$adminApiKey = ApiKey::create();
|
||||
@@ -158,7 +159,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findVisitsByTagReturnsProperData(): void
|
||||
{
|
||||
$foo = 'foo';
|
||||
@@ -183,7 +184,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countVisitsByTagReturnsProperData(): void
|
||||
{
|
||||
$foo = 'foo';
|
||||
@@ -205,7 +206,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findVisitsByDomainReturnsProperData(): void
|
||||
{
|
||||
$this->createShortUrlsAndVisits('s.test');
|
||||
@@ -229,7 +230,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countVisitsByDomainReturnsProperData(): void
|
||||
{
|
||||
$this->createShortUrlsAndVisits('s.test');
|
||||
@@ -253,7 +254,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countVisitsReturnsExpectedResultBasedOnApiKey(): void
|
||||
{
|
||||
$domain = Domain::withAuthority('foo.com');
|
||||
@@ -316,7 +317,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals(3, $this->repo->countOrphanVisits(new VisitsCountFiltering(null, true)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findOrphanVisitsReturnsExpectedResult(): void
|
||||
{
|
||||
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl']));
|
||||
@@ -365,7 +366,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function countOrphanVisitsReturnsExpectedResult(): void
|
||||
{
|
||||
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'longUrl']));
|
||||
@@ -402,7 +403,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findNonOrphanVisitsReturnsExpectedResult(): void
|
||||
{
|
||||
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => '1']));
|
||||
@@ -445,7 +446,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
||||
self::assertCount(5, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 5, 5)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
#[Test]
|
||||
public function findMostRecentOrphanVisitReturnsExpectedVisit(): void
|
||||
{
|
||||
$this->assertNull($this->repo->findMostRecentOrphanVisit());
|
||||
|
||||
Reference in New Issue
Block a user