2020-02-02 06:15:08 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Utils;
|
|
|
|
|
2021-01-10 02:02:05 -06:00
|
|
|
use GuzzleHttp\Psr7\Query;
|
2020-02-02 06:15:08 -06:00
|
|
|
use Laminas\Diactoros\Uri;
|
|
|
|
|
|
|
|
use function sprintf;
|
|
|
|
|
|
|
|
trait NotFoundUrlHelpersTrait
|
|
|
|
{
|
|
|
|
public function provideInvalidUrls(): iterable
|
|
|
|
{
|
2021-01-10 02:02:05 -06:00
|
|
|
yield 'invalid shortcode' => ['invalid', null, 'No URL found with short code "invalid"', 'valid_api_key'];
|
2020-02-02 12:15:14 -06:00
|
|
|
yield 'invalid shortcode without domain' => [
|
2020-02-02 06:15:08 -06:00
|
|
|
'abc123',
|
|
|
|
'example.com',
|
|
|
|
'No URL found with short code "abc123" for domain "example.com"',
|
2021-01-10 02:02:05 -06:00
|
|
|
'valid_api_key',
|
2020-02-02 06:15:08 -06:00
|
|
|
];
|
2020-02-02 12:15:14 -06:00
|
|
|
yield 'invalid shortcode + domain' => [
|
|
|
|
'custom-with-domain',
|
|
|
|
'example.com',
|
|
|
|
'No URL found with short code "custom-with-domain" for domain "example.com"',
|
2021-01-10 02:02:05 -06:00
|
|
|
'valid_api_key',
|
|
|
|
];
|
|
|
|
yield 'valid shortcode with invalid API key' => [
|
|
|
|
'ghi789',
|
|
|
|
null,
|
|
|
|
'No URL found with short code "ghi789"',
|
|
|
|
'author_api_key',
|
|
|
|
];
|
|
|
|
yield 'valid shortcode + 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',
|
2020-02-02 12:15:14 -06:00
|
|
|
];
|
2020-02-02 06:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildShortUrlPath(string $shortCode, ?string $domain, string $suffix = ''): string
|
|
|
|
{
|
|
|
|
$url = new Uri(sprintf('/short-urls/%s%s', $shortCode, $suffix));
|
|
|
|
if ($domain !== null) {
|
2021-01-10 02:02:05 -06:00
|
|
|
$url = $url->withQuery(Query::build(['domain' => $domain]));
|
2020-02-02 06:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return (string) $url;
|
|
|
|
}
|
|
|
|
}
|