Replace traits with external data providers in API tests

This commit is contained in:
Alejandro Celaya
2023-06-18 10:36:45 +02:00
parent 3b1f6c69de
commit dc4aab2cab
7 changed files with 60 additions and 41 deletions

View File

@@ -7,16 +7,16 @@ namespace ShlinkioApiTest\Shlink\Rest\Action;
use Cake\Chronos\Chronos;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait;
use ShlinkioApiTest\Shlink\Rest\Utils\ApiTestDataProviders;
use ShlinkioApiTest\Shlink\Rest\Utils\UrlBuilder;
use function sprintf;
class ResolveShortUrlTest extends ApiTestCase
{
use NotFoundUrlHelpersTrait;
#[Test, DataProvider('provideDisabledMeta')]
public function shortUrlIsProperlyResolvedEvenWhenNotEnabled(array $disabledMeta): void
{
@@ -42,14 +42,18 @@ class ResolveShortUrlTest extends ApiTestCase
yield 'maxVisits reached' => [['maxVisits' => 1]];
}
#[Test, DataProvider('provideInvalidUrls')]
#[Test, DataProviderExternal(ApiTestDataProviders::class, 'invalidUrlsProvider')]
public function tryingToResolveInvalidUrlReturnsNotFoundError(
string $shortCode,
?string $domain,
string $expectedDetail,
string $apiKey,
): void {
$resp = $this->callApiWithKey(self::METHOD_GET, $this->buildShortUrlPath($shortCode, $domain), [], $apiKey);
$resp = $this->callApiWithKey(
self::METHOD_GET,
UrlBuilder::buildShortUrlPath($shortCode, $domain),
apiKey: $apiKey,
);
$payload = $this->getJsonResponsePayload($resp);
self::assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode());