HummingBirdAnimeClient/tests/AnimeClient/RoutingBaseTest.php

67 lines
1.8 KiB
PHP
Raw 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-10-09 14:34:55 -04:00
2017-02-15 11:49:38 -05:00
namespace Aviat\AnimeClient\Tests;
2015-10-09 14:34:55 -04:00
use Aviat\AnimeClient\RoutingBase;
2022-03-04 12:19:47 -05:00
use JetBrains\PhpStorm\ArrayShape;
2015-10-09 14:34:55 -04:00
2023-10-27 09:28:06 -04:00
class ConcreteRoutingBase extends RoutingBase {}
2022-03-04 12:19:47 -05:00
/**
* @internal
*/
final class RoutingBaseTest extends AnimeClientTestCase
{
2022-03-04 12:25:29 -05:00
#[ArrayShape(['empty_segment' => 'array', 'three_segments' => 'array'])]
2023-05-09 12:46:52 -04:00
public static function dataSegments()
2015-10-09 14:34:55 -04:00
{
return [
'empty_segment' => [
2017-02-15 11:57:29 -05:00
'requestUri' => ' // ',
2015-10-09 14:34:55 -04:00
'path' => '/',
'segments' => ['', ''],
2022-03-04 12:19:47 -05:00
'lastSegment' => NULL,
2015-10-09 14:34:55 -04:00
],
'three_segments' => [
2017-02-15 11:57:29 -05:00
'requestUri' => '/anime/watching/list ',
2015-10-09 14:34:55 -04:00
'path' => '/anime/watching/list',
'segments' => ['', 'anime', 'watching', 'list'],
2022-03-04 12:19:47 -05:00
'lastSegment' => 'list',
],
2015-10-09 14:34:55 -04:00
];
}
2023-05-09 12:46:52 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('dataSegments')]
public function testSegments(string $requestUri, string $path, array $segments, ?string $lastSegment): void
{
$this->setSuperGlobals([
'_SERVER' => [
'REQUEST_URI' => $requestUri,
],
]);
2015-10-09 14:34:55 -04:00
2023-10-27 09:28:06 -04:00
$routingBase = new ConcreteRoutingBase($this->container);
2019-01-07 09:08:00 -05:00
2023-05-09 12:46:52 -04:00
$this->assertSame($path, $routingBase->path(), 'Path is invalid');
$this->assertSame($segments, $routingBase->segments(), 'Segments array is invalid');
$this->assertEquals($lastSegment, $routingBase->lastSegment(), 'Last segment is invalid');
2015-10-09 14:34:55 -04:00
2023-05-09 12:46:52 -04:00
foreach ($segments as $i => $value)
{
$this->assertEquals($value, $routingBase->getSegment($i), "Segment {$i} is invalid");
}
}
2022-03-04 12:19:47 -05:00
}