HummingBirdAnimeClient/tests/AnimeClient/UrlGeneratorTest.php

62 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
2018-08-22 13:48:27 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2023-07-13 11:08:05 -04:00
* PHP version 8.1
*
2023-07-13 11:08:05 -04:00
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2023-07-13 11:08:05 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
2015-09-14 15:49:20 -04:00
2017-02-15 11:49:38 -05:00
namespace Aviat\AnimeClient\Tests;
2015-09-15 13:19:29 -04:00
use Aviat\AnimeClient\UrlGenerator;
2022-03-04 12:19:47 -05:00
use InvalidArgumentException;
2023-05-09 12:46:52 -04:00
use PHPUnit\Framework\Attributes\DataProvider;
2015-09-14 15:49:20 -04:00
2022-03-04 12:19:47 -05:00
/**
* @internal
*/
final class UrlGeneratorTest extends AnimeClientTestCase
{
2023-05-09 12:46:52 -04:00
public static function assetUrlProvider(): array
2015-09-14 15:49:20 -04:00
{
return [
'single argument' => [
'args' => [
2022-03-04 12:19:47 -05:00
'images',
2015-09-14 15:49:20 -04:00
],
2018-10-11 09:53:14 -04:00
'expected' => 'https://localhost/assets/images',
2015-09-14 15:49:20 -04:00
],
'multiple arguments' => [
'args' => [
2022-03-04 12:19:47 -05:00
'images', 'anime', 'foo.png',
2015-09-14 15:49:20 -04:00
],
2022-03-04 12:19:47 -05:00
'expected' => 'https://localhost/assets/images/anime/foo.png',
],
2015-09-14 15:49:20 -04:00
];
}
2023-05-09 12:46:52 -04:00
#[DataProvider('assetUrlProvider')]
public function testAssetUrl(mixed $args, string $expected): void
2015-09-14 15:49:20 -04:00
{
$urlGenerator = new UrlGenerator($this->container);
2017-02-15 15:56:10 -05:00
$result = $urlGenerator->assetUrl(...$args);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $result);
2015-09-14 15:49:20 -04:00
}
2020-12-10 17:04:45 -05:00
public function testDefaultUrlInvalidType(): void
{
2022-03-04 12:19:47 -05:00
$this->expectException(InvalidArgumentException::class);
2020-12-10 17:04:45 -05:00
$this->expectExceptionMessage("Invalid default type: 'foo'");
$urlGenerator = new UrlGenerator($this->container);
$url = $urlGenerator->defaultUrl('foo');
}
2022-03-04 12:19:47 -05:00
}