166 lines
3.9 KiB
PHP
166 lines
3.9 KiB
PHP
<?php declare(strict_types=1);
|
|
/**
|
|
* Hummingbird Anime List Client
|
|
*
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
|
*
|
|
* PHP version 8
|
|
*
|
|
* @copyright 2015 - 2022 Timothy J. Warren <tim@timshome.page>
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
* @version 5.2
|
|
* @link https://git.timshome.page/timw4mail/HummingBirdAnimeClient
|
|
*/
|
|
|
|
namespace Aviat\Ion\Tests\Transformer;
|
|
|
|
use Aviat\Ion\Tests\IonTestCase;
|
|
use Aviat\Ion\Tests\{TestTransformer, TestTransformerUntransform};
|
|
use BadMethodCallException;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class AbstractTransformerTest extends IonTestCase
|
|
{
|
|
protected $transformer;
|
|
protected $untransformer;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->transformer = new TestTransformer();
|
|
$this->untransformer = new TestTransformerUntransform();
|
|
}
|
|
|
|
public function dataTransformCollection()
|
|
{
|
|
return [
|
|
'object' => [
|
|
'original' => [
|
|
(object) [
|
|
['name' => 'Comedy'],
|
|
['name' => 'Romance'],
|
|
['name' => 'School'],
|
|
['name' => 'Harem'],
|
|
],
|
|
(object) [
|
|
['name' => 'Action'],
|
|
['name' => 'Comedy'],
|
|
['name' => 'Magic'],
|
|
['name' => 'Fantasy'],
|
|
['name' => 'Mahou Shoujo'],
|
|
],
|
|
(object) [
|
|
['name' => 'Comedy'],
|
|
['name' => 'Sci-Fi'],
|
|
],
|
|
],
|
|
'expected' => [
|
|
['Comedy', 'Romance', 'School', 'Harem'],
|
|
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
['Comedy', 'Sci-Fi'],
|
|
],
|
|
],
|
|
'array' => [
|
|
'original' => [
|
|
[
|
|
['name' => 'Comedy'],
|
|
['name' => 'Romance'],
|
|
['name' => 'School'],
|
|
['name' => 'Harem'],
|
|
],
|
|
[
|
|
['name' => 'Action'],
|
|
['name' => 'Comedy'],
|
|
['name' => 'Magic'],
|
|
['name' => 'Fantasy'],
|
|
['name' => 'Mahou Shoujo'],
|
|
],
|
|
[
|
|
['name' => 'Comedy'],
|
|
['name' => 'Sci-Fi'],
|
|
],
|
|
],
|
|
'expected' => [
|
|
['Comedy', 'Romance', 'School', 'Harem'],
|
|
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
['Comedy', 'Sci-Fi'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function dataUnTransformCollection()
|
|
{
|
|
return [
|
|
'object' => [
|
|
'original' => [
|
|
(object) ['Comedy', 'Romance', 'School', 'Harem'],
|
|
(object) ['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
(object) ['Comedy', 'Sci-Fi'],
|
|
],
|
|
'expected' => [
|
|
['Comedy', 'Romance', 'School', 'Harem'],
|
|
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
['Comedy', 'Sci-Fi'],
|
|
],
|
|
],
|
|
'array' => [
|
|
'original' => [
|
|
['Comedy', 'Romance', 'School', 'Harem'],
|
|
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
['Comedy', 'Sci-Fi'],
|
|
],
|
|
'expected' => [
|
|
['Comedy', 'Romance', 'School', 'Harem'],
|
|
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
|
|
['Comedy', 'Sci-Fi'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function testTransform()
|
|
{
|
|
$data = $this->dataTransformCollection();
|
|
$original = $data['object']['original'][0];
|
|
$expected = $data['object']['expected'][0];
|
|
|
|
$actual = $this->transformer->transform($original);
|
|
$this->assertSame($expected, $actual);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataTransformCollection
|
|
* @param mixed $original
|
|
* @param mixed $expected
|
|
*/
|
|
public function testTransformCollection($original, $expected)
|
|
{
|
|
$actual = $this->transformer->transformCollection($original);
|
|
$this->assertSame($expected, $actual);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataUnTransformCollection
|
|
* @param mixed $original
|
|
* @param mixed $expected
|
|
*/
|
|
public function testUntransformCollection($original, $expected)
|
|
{
|
|
$actual = $this->untransformer->untransformCollection($original);
|
|
$this->assertSame($expected, $actual);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataUnTransformCollection
|
|
* @param mixed $original
|
|
* @param mixed $expected
|
|
*/
|
|
public function testUntransformCollectionWithException($original, $expected)
|
|
{
|
|
$this->expectException(BadMethodCallException::class);
|
|
$this->transformer->untransformCollection($original);
|
|
}
|
|
}
|