mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Replace traits with external data providers in API tests
This commit is contained in:
@@ -4,14 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Utils;
|
||||
|
||||
use GuzzleHttp\Psr7\Query;
|
||||
use Laminas\Diactoros\Uri;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
trait NotFoundUrlHelpersTrait
|
||||
class ApiTestDataProviders
|
||||
{
|
||||
public static function provideInvalidUrls(): iterable
|
||||
public static function invalidUrlsProvider(): iterable
|
||||
{
|
||||
yield 'invalid shortcode' => ['invalid', null, 'No URL found with short code "invalid"', 'valid_api_key'];
|
||||
yield 'invalid shortcode without domain' => [
|
||||
@@ -20,7 +15,7 @@ trait NotFoundUrlHelpersTrait
|
||||
'No URL found with short code "abc123" for domain "example.com"',
|
||||
'valid_api_key',
|
||||
];
|
||||
yield 'invalid shortcode + domain' => [
|
||||
yield 'invalid shortcode and custom domain' => [
|
||||
'custom-with-domain',
|
||||
'example.com',
|
||||
'No URL found with short code "custom-with-domain" for domain "example.com"',
|
||||
@@ -32,21 +27,11 @@ trait NotFoundUrlHelpersTrait
|
||||
'No URL found with short code "ghi789"',
|
||||
'author_api_key',
|
||||
];
|
||||
yield 'valid shortcode + domain with invalid API key' => [
|
||||
yield 'valid shortcode and custom domain with invalid API key' => [
|
||||
'custom-with-domain',
|
||||
'some-domain.com',
|
||||
'No URL found with short code "custom-with-domain" for domain "some-domain.com"',
|
||||
'domain_api_key',
|
||||
];
|
||||
}
|
||||
|
||||
public function buildShortUrlPath(string $shortCode, ?string $domain, string $suffix = ''): string
|
||||
{
|
||||
$url = new Uri(sprintf('/short-urls/%s%s', $shortCode, $suffix));
|
||||
if ($domain !== null) {
|
||||
$url = $url->withQuery(Query::build(['domain' => $domain]));
|
||||
}
|
||||
|
||||
return (string) $url;
|
||||
}
|
||||
}
|
||||
23
module/Rest/test-api/Utils/UrlBuilder.php
Normal file
23
module/Rest/test-api/Utils/UrlBuilder.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Utils;
|
||||
|
||||
use GuzzleHttp\Psr7\Query;
|
||||
use Laminas\Diactoros\Uri;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class UrlBuilder
|
||||
{
|
||||
public static function buildShortUrlPath(string $shortCode, ?string $domain, string $suffix = ''): string
|
||||
{
|
||||
$url = new Uri(sprintf('/short-urls/%s%s', $shortCode, $suffix));
|
||||
if ($domain !== null) {
|
||||
$url = $url->withQuery(Query::build(['domain' => $domain]));
|
||||
}
|
||||
|
||||
return $url->__toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user