mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Replace traits with external data providers in Core unit tests
This commit is contained in:
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\ShortUrl;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -14,14 +14,12 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlListRepositoryInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlListService;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyDataProviders;
|
||||
|
||||
use function count;
|
||||
|
||||
class ShortUrlListServiceTest extends TestCase
|
||||
{
|
||||
use ApiKeyHelpersTrait;
|
||||
|
||||
private ShortUrlListService $service;
|
||||
private MockObject & ShortUrlListRepositoryInterface $repo;
|
||||
|
||||
@@ -31,7 +29,7 @@ class ShortUrlListServiceTest extends TestCase
|
||||
$this->service = new ShortUrlListService($this->repo, new UrlShortenerOptions());
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideAdminApiKeys')]
|
||||
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
||||
public function listedUrlsAreReturnedFromEntityManager(?ApiKey $apiKey): void
|
||||
{
|
||||
$list = [
|
||||
|
||||
@@ -8,6 +8,7 @@ use Cake\Chronos\Chronos;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -22,15 +23,13 @@ use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolver;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyDataProviders;
|
||||
|
||||
use function Functional\map;
|
||||
use function range;
|
||||
|
||||
class ShortUrlResolverTest extends TestCase
|
||||
{
|
||||
use ApiKeyHelpersTrait;
|
||||
|
||||
private ShortUrlResolver $urlResolver;
|
||||
private MockObject & EntityManagerInterface $em;
|
||||
private MockObject & ShortUrlRepositoryInterface $repo;
|
||||
@@ -42,7 +41,7 @@ class ShortUrlResolverTest extends TestCase
|
||||
$this->urlResolver = new ShortUrlResolver($this->em, new UrlShortenerOptions());
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideAdminApiKeys')]
|
||||
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
||||
public function shortCodeIsProperlyParsed(?ApiKey $apiKey): void
|
||||
{
|
||||
$shortUrl = ShortUrl::withLongUrl('https://expected_url');
|
||||
@@ -59,7 +58,7 @@ class ShortUrlResolverTest extends TestCase
|
||||
self::assertSame($shortUrl, $result);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideAdminApiKeys')]
|
||||
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
||||
public function exceptionIsThrownIfShortcodeIsNotFound(?ApiKey $apiKey): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
|
||||
@@ -21,15 +21,12 @@ use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlService;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
|
||||
|
||||
use function array_fill_keys;
|
||||
use function Shlinkio\Shlink\Core\enumValues;
|
||||
|
||||
class ShortUrlServiceTest extends TestCase
|
||||
{
|
||||
use ApiKeyHelpersTrait;
|
||||
|
||||
private ShortUrlService $service;
|
||||
private MockObject & ShortUrlResolverInterface $urlResolver;
|
||||
private MockObject & ShortUrlTitleResolutionHelperInterface $titleResolutionHelper;
|
||||
|
||||
Reference in New Issue
Block a user