From d91665e3ae275f9febc0c38bd4596e6b6248c3a0 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 3 Apr 2017 14:46:29 -0400 Subject: [PATCH 1/4] More basic tests, see #16 --- src/API/Mapping/AnimeWatchingStatus.php | 7 +--- src/API/Mapping/MangaReadingStatus.php | 7 +--- .../Transformer/AnimeListTransformerTest.php | 39 +++++++++++++++++++ .../Transformer/MangaListTransformerTest.php | 39 +++++++++++++++++++ 4 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 tests/API/MAL/Transformer/AnimeListTransformerTest.php create mode 100644 tests/API/MAL/Transformer/MangaListTransformerTest.php diff --git a/src/API/Mapping/AnimeWatchingStatus.php b/src/API/Mapping/AnimeWatchingStatus.php index 34b44930..0017775c 100644 --- a/src/API/Mapping/AnimeWatchingStatus.php +++ b/src/API/Mapping/AnimeWatchingStatus.php @@ -16,12 +16,7 @@ namespace Aviat\AnimeClient\API\Mapping; -use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{ - Kitsu, - MAL, - Route, - Title -}; +use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{Kitsu, MAL, Route, Title}; use Aviat\Ion\Enum; /** diff --git a/src/API/Mapping/MangaReadingStatus.php b/src/API/Mapping/MangaReadingStatus.php index 363483da..c509a0bb 100644 --- a/src/API/Mapping/MangaReadingStatus.php +++ b/src/API/Mapping/MangaReadingStatus.php @@ -16,12 +16,7 @@ namespace Aviat\AnimeClient\API\Mapping; -use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{ - Kitsu, - MAL, - Title, - Route -}; +use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{Kitsu, MAL, Title, Route}; use Aviat\Ion\Enum; /** diff --git a/tests/API/MAL/Transformer/AnimeListTransformerTest.php b/tests/API/MAL/Transformer/AnimeListTransformerTest.php new file mode 100644 index 00000000..bc5007ea --- /dev/null +++ b/tests/API/MAL/Transformer/AnimeListTransformerTest.php @@ -0,0 +1,39 @@ + + * @copyright 2015 - 2017 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 4.0 + * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient + */ + +namespace Aviat\AnimeClient\Tests\API\MAL\Transformer; + +use Aviat\AnimeClient\API\MAL\Transformer\AnimeListTransformer; +use Aviat\AnimeClient\Tests\AnimeClientTestCase; +use Aviat\Ion\Friend; +use Aviat\Ion\Json; + +class AnimeListTransformerTest extends AnimeClientTestCase { + + protected $transformer; + + public function setUp() + { + parent::setUp(); + $this->transformer = new AnimeListTransformer(); + } + + public function testTransform() + { + $this->assertEquals([], $this->transformer->transform([])); + } + +} \ No newline at end of file diff --git a/tests/API/MAL/Transformer/MangaListTransformerTest.php b/tests/API/MAL/Transformer/MangaListTransformerTest.php new file mode 100644 index 00000000..6a6a6196 --- /dev/null +++ b/tests/API/MAL/Transformer/MangaListTransformerTest.php @@ -0,0 +1,39 @@ + + * @copyright 2015 - 2017 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 4.0 + * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient + */ + +namespace Aviat\AnimeClient\Tests\API\MAL\Transformer; + +use Aviat\AnimeClient\API\MAL\Transformer\MangaListTransformer; +use Aviat\AnimeClient\Tests\AnimeClientTestCase; +use Aviat\Ion\Friend; +use Aviat\Ion\Json; + +class MangaListTransformerTest extends AnimeClientTestCase { + + protected $transformer; + + public function setUp() + { + parent::setUp(); + $this->transformer = new MangaListTransformer(); + } + + public function testTransform() + { + $this->assertEquals([], $this->transformer->transform([])); + } + +} \ No newline at end of file From 388c0a274dc42c47a45bba6baeefd1f5596b084e Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 3 Apr 2017 15:46:16 -0400 Subject: [PATCH 2/4] Fix creating missing Kitsu items --- src/Command/SyncKitsuWithMal.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/SyncKitsuWithMal.php b/src/Command/SyncKitsuWithMal.php index 706a4aaa..9218eaec 100644 --- a/src/Command/SyncKitsuWithMal.php +++ b/src/Command/SyncKitsuWithMal.php @@ -90,7 +90,7 @@ class SyncKitsuWithMal extends BaseCommand { if ( ! empty($data['addToKitsu'])) { $this->echoBox("Adding missing anime list items to Kitsu"); - $this->createKitusListItems($data['addToKitsu'], 'anime'); + $this->createKitsuListItems($data['addToKitsu'], 'anime'); } } @@ -373,7 +373,7 @@ class SyncKitsuWithMal extends BaseCommand { ]; } - public function createKitusAnimeListItems($itemsToAdd, $type = 'anime') + public function createKitsuListItems($itemsToAdd, $type = 'anime') { $requester = new ParallelAPIRequest(); foreach($itemsToAdd as $item) From 06a92a5a8e1cb1b3b75803990b75eae94cba92d6 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 3 Apr 2017 16:49:40 -0400 Subject: [PATCH 3/4] Fix collection images, resolves #26 --- app/views/collection/cover.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/collection/cover.php b/app/views/collection/cover.php index c6b936e9..94690f56 100644 --- a/app/views/collection/cover.php +++ b/app/views/collection/cover.php @@ -11,7 +11,8 @@
- <?= $item['title'] ?> cover image + <?= $item['title'] ?> cover image
From 255895097aa62b66170399d919ee35e6c8328c58 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 3 Apr 2017 16:53:04 -0400 Subject: [PATCH 4/4] Remove some dead code --- src/API/JsonAPI.php | 67 +++++++-------------------------------------- 1 file changed, 10 insertions(+), 57 deletions(-) diff --git a/src/API/JsonAPI.php b/src/API/JsonAPI.php index 105d377a..b23eb090 100644 --- a/src/API/JsonAPI.php +++ b/src/API/JsonAPI.php @@ -57,7 +57,7 @@ class JsonAPI { $included = static::organizeIncluded($data['included']); // Inline organized data - foreach($data['data'] as $i => $item) + foreach($data['data'] as $i => &$item) { if (array_key_exists('relationships', $item)) { @@ -66,11 +66,11 @@ class JsonAPI { if (array_keys($props) === ['links']) { - unset($data['data'][$i]['relationships'][$relType]); + unset($item['relationships'][$relType]); - if (empty($data['data'][$i]['relationships'])) + if (empty($item['relationships'])) { - unset($data['data'][$i]['relationships']); + unset($item['relationships']); } continue; @@ -78,18 +78,18 @@ class JsonAPI { if (array_key_exists('links', $props)) { - unset($data['data'][$i]['relationships'][$relType]['links']); + unset($item['relationships'][$relType]['links']); } if (array_key_exists('data', $props)) { if (empty($props['data'])) { - unset($data['data'][$i]['relationships'][$relType]['data']); + unset($item['relationships'][$relType]['data']); - if (empty($data['data'][$i]['relationships'][$relType])) + if (empty($item['relationships'][$relType])) { - unset($data['data'][$i]['relationships'][$relType]); + unset($item['relationships'][$relType]); } continue; @@ -99,7 +99,7 @@ class JsonAPI { { $idKey = $props['data']['id']; $typeKey = $props['data']['type']; - $relationship =& $data['data'][$i]['relationships'][$relType]; + $relationship =& $item['relationships'][$relType]; unset($relationship['data']); if (in_array($relType, $singular)) @@ -123,7 +123,7 @@ class JsonAPI { { $idKey = $props['data'][$j]['id']; $typeKey = $props['data'][$j]['type']; - $relationship =& $data['data'][$i]['relationships'][$relType]; + $relationship =& $item['relationships'][$relType]; unset($relationship['data'][$j]); @@ -235,16 +235,6 @@ class JsonAPI { return $organized; } - public static function inlineRawIncludes(array &$data, string $key): array - { - foreach($data['data'] as $i => &$item) - { - $item[$key] = $data['included'][$i]; - } - - return $data['data']; - } - /** * Take organized includes and inline them, where applicable * @@ -305,17 +295,6 @@ class JsonAPI { return $organized; } - /** - * Reorganize 'included' data - * - * @param array $includes - * @return array - */ - public static function lightlyOrganizeIncludes(array $includes): array - { - return static::organizeIncluded($includes); - } - /** * Reorganize relationship mappings to make them simpler to use * @@ -349,30 +328,4 @@ class JsonAPI { return $organized; } - - public static function fillRelationshipsFromIncludes(array $relationships, array $includes): array - { - $output = []; - - foreach ($relationships as $key => $block) - { - if (array_key_exists('data', $block) && is_array($block['data']) && ! empty($block['data'])) - { - $output[$key] = []; - if (array_key_exists('type', $block['data']) && array_key_exists('id', $block['data'])) - { - $output[$key] = $includes[$block['data']['type']][$block['data']['id']]; - } - else - { - foreach($block['data'] as $dBlock) - { - $output[$key][] = $includes[$dBlock['type']][$dBlock['id']]; - } - } - } - } - - return $output; - } } \ No newline at end of file