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

@@ -9,16 +9,16 @@ use GuzzleHttp\Psr7\Query;
use GuzzleHttp\RequestOptions;
use Laminas\Diactoros\Uri;
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 EditShortUrlTest extends ApiTestCase
{
use NotFoundUrlHelpersTrait;
#[Test, DataProvider('provideMeta')]
public function metadataCanBeReset(array $meta): void
{
@@ -99,14 +99,14 @@ class EditShortUrlTest extends ApiTestCase
yield 'invalid URL' => ['http://foo', self::STATUS_BAD_REQUEST, 'INVALID_URL'];
}
#[Test, DataProvider('provideInvalidUrls')]
#[Test, DataProviderExternal(ApiTestDataProviders::class, 'invalidUrlsProvider')]
public function tryingToEditInvalidUrlReturnsNotFoundError(
string $shortCode,
?string $domain,
string $expectedDetail,
string $apiKey,
): void {
$url = $this->buildShortUrlPath($shortCode, $domain);
$url = UrlBuilder::buildShortUrlPath($shortCode, $domain);
$resp = $this->callApiWithKey(self::METHOD_PATCH, $url, [RequestOptions::JSON => []], $apiKey);
$payload = $this->getJsonResponsePayload($resp);