Moved common data provider for core unit tests to trait

This commit is contained in:
Alejandro Celaya 2021-01-10 09:31:51 +01:00
parent c56d56d38c
commit 5283ee2c6b
5 changed files with 30 additions and 30 deletions

View File

@ -19,12 +19,14 @@ use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface;
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolver;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
use function Functional\map;
use function range;
class ShortUrlResolverTest extends TestCase
{
use ApiKeyHelpersTrait;
use ProphecyTrait;
private ShortUrlResolver $urlResolver;
@ -38,7 +40,7 @@ class ShortUrlResolverTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function shortCodeIsProperlyParsed(?ApiKey $apiKey): void
{
@ -58,7 +60,7 @@ class ShortUrlResolverTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function exceptionIsThrownIfShortcodeIsNotFound(?ApiKey $apiKey): void
{
@ -75,12 +77,6 @@ class ShortUrlResolverTest extends TestCase
$this->urlResolver->resolveShortUrl(new ShortUrlIdentifier($shortCode), $apiKey);
}
public function provideApiKeys(): iterable
{
yield 'no API key' => [null];
yield 'API key' => [new ApiKey()];
}
/** @test */
public function shortCodeToEnabledShortUrlProperlyParsesShortCode(): void
{

View File

@ -21,11 +21,13 @@ use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Core\Util\UrlValidatorInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
use function count;
class ShortUrlServiceTest extends TestCase
{
use ApiKeyHelpersTrait;
use ProphecyTrait;
private ShortUrlService $service;
@ -51,7 +53,7 @@ class ShortUrlServiceTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function listedUrlsAreReturnedFromEntityManager(?ApiKey $apiKey): void
{
@ -73,7 +75,7 @@ class ShortUrlServiceTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function providedTagsAreGetFromRepoAndSetToTheShortUrl(?ApiKey $apiKey): void
{
@ -92,12 +94,6 @@ class ShortUrlServiceTest extends TestCase
$this->service->setTagsByShortCode(new ShortUrlIdentifier($shortCode), ['foo', 'bar'], $apiKey);
}
public function provideApiKeys(): iterable
{
yield 'no API key' => [null];
yield 'API key' => [new ApiKey()];
}
/**
* @test
* @dataProvider provideShortUrlEdits

View File

@ -19,9 +19,11 @@ use Shlinkio\Shlink\Core\Tag\Model\TagRenaming;
use Shlinkio\Shlink\Core\Tag\TagService;
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
class TagServiceTest extends TestCase
{
use ApiKeyHelpersTrait;
use ProphecyTrait;
private TagService $service;
@ -165,12 +167,6 @@ class TagServiceTest extends TestCase
$this->service->renameTag(TagRenaming::fromNames('foo', 'bar'), $apiKey);
}
public function provideAdminApiKeys(): iterable
{
yield 'no API key' => [null];
yield 'admin API key' => [new ApiKey()];
}
/** @test */
public function renamingTagThrowsExceptionWhenProvidedApiKeyIsNotAdmin(): void
{

View File

@ -26,12 +26,14 @@ use Shlinkio\Shlink\Core\Repository\TagRepository;
use Shlinkio\Shlink\Core\Repository\VisitRepository;
use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use ShlinkioTest\Shlink\Core\Util\ApiKeyHelpersTrait;
use function Functional\map;
use function range;
class VisitsTrackerTest extends TestCase
{
use ApiKeyHelpersTrait;
use ProphecyTrait;
private VisitsTracker $visitsTracker;
@ -61,7 +63,7 @@ class VisitsTrackerTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function infoReturnsVisitsForCertainShortCode(?ApiKey $apiKey): void
{
@ -117,7 +119,7 @@ class VisitsTrackerTest extends TestCase
/**
* @test
* @dataProvider provideApiKeys
* @dataProvider provideAdminApiKeys
*/
public function visitsForTagAreReturnedAsExpected(?ApiKey $apiKey): void
{
@ -139,10 +141,4 @@ class VisitsTrackerTest extends TestCase
$tagExists->shouldHaveBeenCalledOnce();
$getRepo->shouldHaveBeenCalledOnce();
}
public function provideApiKeys(): iterable
{
yield 'no API key' => [null];
yield 'API key' => [new ApiKey()];
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Util;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
trait ApiKeyHelpersTrait
{
public function provideAdminApiKeys(): iterable
{
yield 'no API key' => [null];
yield 'admin API key' => [new ApiKey()];
}
}