HummingBirdAnimeClient/tests/Ion/Transformer/AbstractTransformerTest.php

168 lines
4.0 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
/**
2020-03-12 11:45:11 -04:00
* Hummingbird Anime List Client
*
2020-03-12 11:45:11 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2021-02-04 11:57:01 -05:00
* PHP version 8
*
2020-03-12 11:45:11 -04:00
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2021-01-13 01:52:03 -05:00
* @copyright 2015 - 2021 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2020-03-12 11:45:11 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\Ion\Tests\Transformer;
2020-03-12 09:52:45 -04:00
use Aviat\Ion\Tests\IonTestCase;
use Aviat\Ion\Tests\{TestTransformer, TestTransformerUntransform};
2022-03-04 12:19:47 -05:00
use BadMethodCallException;
2022-03-04 12:19:47 -05:00
/**
* @internal
*/
final class AbstractTransformerTest extends IonTestCase
{
protected $transformer;
protected $untransformer;
2022-03-04 12:19:47 -05:00
protected function setUp(): void
{
$this->transformer = new TestTransformer();
$this->untransformer = new TestTransformerUntransform();
}
public function dataTransformCollection()
{
return [
'object' => [
'original' => [
2022-03-04 12:19:47 -05:00
(object) [
['name' => 'Comedy'],
['name' => 'Romance'],
['name' => 'School'],
2022-03-04 12:19:47 -05:00
['name' => 'Harem'],
],
2022-03-04 12:19:47 -05:00
(object) [
['name' => 'Action'],
['name' => 'Comedy'],
['name' => 'Magic'],
['name' => 'Fantasy'],
2022-03-04 12:19:47 -05:00
['name' => 'Mahou Shoujo'],
],
2022-03-04 12:19:47 -05:00
(object) [
['name' => 'Comedy'],
2022-03-04 12:19:47 -05:00
['name' => 'Sci-Fi'],
],
],
'expected' => [
['Comedy', 'Romance', 'School', 'Harem'],
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
2022-03-04 12:19:47 -05:00
['Comedy', 'Sci-Fi'],
],
],
'array' => [
'original' => [
[
['name' => 'Comedy'],
['name' => 'Romance'],
['name' => 'School'],
2022-03-04 12:19:47 -05:00
['name' => 'Harem'],
],
[
['name' => 'Action'],
['name' => 'Comedy'],
['name' => 'Magic'],
['name' => 'Fantasy'],
2022-03-04 12:19:47 -05:00
['name' => 'Mahou Shoujo'],
],
[
['name' => 'Comedy'],
2022-03-04 12:19:47 -05:00
['name' => 'Sci-Fi'],
],
],
'expected' => [
['Comedy', 'Romance', 'School', 'Harem'],
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
2022-03-04 12:19:47 -05:00
['Comedy', 'Sci-Fi'],
],
],
];
}
public function dataUnTransformCollection()
{
return [
'object' => [
'original' => [
2022-03-04 12:19:47 -05:00
(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'],
2022-03-04 12:19:47 -05:00
['Comedy', 'Sci-Fi'],
],
],
'array' => [
'original' => [
['Comedy', 'Romance', 'School', 'Harem'],
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
2022-03-04 12:19:47 -05:00
['Comedy', 'Sci-Fi'],
],
'expected' => [
['Comedy', 'Romance', 'School', 'Harem'],
['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'],
2022-03-04 12:19:47 -05:00
['Comedy', 'Sci-Fi'],
],
],
];
}
public function testTransform()
{
$data = $this->dataTransformCollection();
$original = $data['object']['original'][0];
$expected = $data['object']['expected'][0];
$actual = $this->transformer->transform($original);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $actual);
}
/**
* @dataProvider dataTransformCollection
2022-03-04 12:19:47 -05:00
* @param mixed $original
* @param mixed $expected
*/
public function testTransformCollection($original, $expected)
{
$actual = $this->transformer->transformCollection($original);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $actual);
}
/**
* @dataProvider dataUnTransformCollection
2022-03-04 12:19:47 -05:00
* @param mixed $original
* @param mixed $expected
*/
public function testUntransformCollection($original, $expected)
{
$actual = $this->untransformer->untransformCollection($original);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $actual);
}
/**
* @dataProvider dataUnTransformCollection
2022-03-04 12:19:47 -05:00
* @param mixed $original
* @param mixed $expected
*/
public function testUntransformCollectionWithException($original, $expected)
{
2022-03-04 12:19:47 -05:00
$this->expectException(BadMethodCallException::class);
$this->transformer->untransformCollection($original);
}
2022-03-04 12:19:47 -05:00
}