2020-02-02 06:15:08 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Utils;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\Uri;
|
|
|
|
|
|
|
|
use function GuzzleHttp\Psr7\build_query;
|
|
|
|
use function sprintf;
|
|
|
|
|
|
|
|
trait NotFoundUrlHelpersTrait
|
|
|
|
{
|
|
|
|
public function provideInvalidUrls(): iterable
|
|
|
|
{
|
|
|
|
yield 'invalid shortcode' => ['invalid', null, 'No URL found with short code "invalid"'];
|
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"',
|
|
|
|
];
|
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"',
|
|
|
|
];
|
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) {
|
|
|
|
$url = $url->withQuery(build_query(['domain' => $domain]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (string) $url;
|
|
|
|
}
|
|
|
|
}
|