From 42d36ff4bb90206c085bbcfad1f45d5d3aba9550 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 13 Apr 2017 11:54:58 -0400 Subject: [PATCH] Update manga transformer tests --- .../Transformer/MangaListTransformerTest.php | 9 +- .../Transformer/MangaTransformerTest.php | 17 +- ...aListTransformerTest__testTransform__1.php | 206 ++++++++++++++++++ ...MangaTransformerTest__testTransform__1.php | 21 ++ 4 files changed, 237 insertions(+), 16 deletions(-) create mode 100644 tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.php create mode 100644 tests/API/Kitsu/Transformer/__snapshots__/MangaTransformerTest__testTransform__1.php diff --git a/tests/API/Kitsu/Transformer/MangaListTransformerTest.php b/tests/API/Kitsu/Transformer/MangaListTransformerTest.php index 9cbfc539..dd1cc8ca 100644 --- a/tests/API/Kitsu/Transformer/MangaListTransformerTest.php +++ b/tests/API/Kitsu/Transformer/MangaListTransformerTest.php @@ -47,19 +47,15 @@ class MangaListTransformerTest extends AnimeClientTestCase { } $this->beforeTransform = $rawBefore['data']; - $this->afterTransform = Json::decodeFile("{$this->dir}/mangaListAfterTransform.json"); + // $this->afterTransform = Json::decodeFile("{$this->dir}/mangaListAfterTransform.json"); $this->transformer = new MangaListTransformer(); } public function testTransform() { - $expected = $this->afterTransform; $actual = $this->transformer->transformCollection($this->beforeTransform); - - // Json::encodeFile("{$this->dir}/mangaListAfterTransform.json", $actual); - - $this->assertEquals($expected, $actual); + $this->assertMatchesSnapshot($actual); } public function testUntransform() @@ -69,6 +65,7 @@ class MangaListTransformerTest extends AnimeClientTestCase { 'mal_id' => '26769', 'chapters_read' => 67, 'manga' => [ + 'id' => '12345', 'titles' => ["Bokura wa Minna Kawaisou"], 'alternate_title' => NULL, 'slug' => "bokura-wa-minna-kawaisou", diff --git a/tests/API/Kitsu/Transformer/MangaTransformerTest.php b/tests/API/Kitsu/Transformer/MangaTransformerTest.php index f4d69747..0c31fcc8 100644 --- a/tests/API/Kitsu/Transformer/MangaTransformerTest.php +++ b/tests/API/Kitsu/Transformer/MangaTransformerTest.php @@ -22,32 +22,29 @@ use Aviat\AnimeClient\Tests\AnimeClientTestCase; use Aviat\Ion\Json; class MangaTransformerTest extends AnimeClientTestCase { - + protected $dir; protected $beforeTransform; protected $afterTransform; protected $transformer; - public function setUp() + public function setUp() { parent::setUp(); $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; - + $data = Json::decodeFile("{$this->dir}/mangaBeforeTransform.json"); $baseData = $data['data'][0]['attributes']; $baseData['included'] = $data['included']; + $baseData['id'] = $data['data'][0]['id']; $this->beforeTransform = $baseData; - $this->afterTransform = Json::decodeFile("{$this->dir}/mangaAfterTransform.json"); - + $this->transformer = new MangaTransformer(); } - + public function testTransform() { $actual = $this->transformer->transform($this->beforeTransform); - $expected = $this->afterTransform; - //Json::encodeFile("{$this->dir}/mangaAfterTransform.json", $actual); - - $this->assertEquals($expected, $actual); + $this->assertMatchesSnapshot($actual); } } \ No newline at end of file diff --git a/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.php b/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.php new file mode 100644 index 00000000..49334993 --- /dev/null +++ b/tests/API/Kitsu/Transformer/__snapshots__/MangaListTransformerTest__testTransform__1.php @@ -0,0 +1,206 @@ + + array ( + 'id' => '15084773', + 'mal_id' => '26769', + 'chapters' => + array ( + 'read' => 67, + 'total' => '-', + ), + 'volumes' => + array ( + 'read' => '-', + 'total' => '-', + ), + 'manga' => + array ( + 'id' => '20286', + 'titles' => + array ( + 0 => 'Bokura wa Minna Kawaisou', + ), + 'alternate_title' => NULL, + 'slug' => 'bokura-wa-minna-kawaisou', + 'url' => 'https://kitsu.io/manga/bokura-wa-minna-kawaisou', + 'type' => 'manga', + 'image' => 'https://media.kitsu.io/manga/poster_images/20286/small.jpg?1434293999', + 'genres' => + array ( + 0 => 'Comedy', + 1 => 'Romance', + 2 => 'School', + 3 => 'Slice of Life', + 4 => 'Thriller', + ), + ), + 'reading_status' => 'current', + 'notes' => '', + 'rereading' => false, + 'reread' => 0, + 'user_rating' => 9.0, + ), + 1 => + array ( + 'id' => '15085607', + 'mal_id' => '16', + 'chapters' => + array ( + 'read' => 17, + 'total' => 120, + ), + 'volumes' => + array ( + 'read' => '-', + 'total' => 14, + ), + 'manga' => + array ( + 'id' => '47', + 'titles' => + array ( + 0 => 'Love Hina', + ), + 'alternate_title' => NULL, + 'slug' => 'love-hina', + 'url' => 'https://kitsu.io/manga/love-hina', + 'type' => 'manga', + 'image' => 'https://media.kitsu.io/manga/poster_images/47/small.jpg?1434249493', + 'genres' => + array ( + 0 => 'Comedy', + 1 => 'Ecchi', + 2 => 'Harem', + 3 => 'Romance', + 4 => 'Sports', + ), + ), + 'reading_status' => 'current', + 'notes' => '', + 'rereading' => false, + 'reread' => 0, + 'user_rating' => 7.0, + ), + 2 => + array ( + 'id' => '15084529', + 'mal_id' => '35003', + 'chapters' => + array ( + 'read' => 16, + 'total' => '-', + ), + 'volumes' => + array ( + 'read' => '-', + 'total' => '-', + ), + 'manga' => + array ( + 'id' => '11777', + 'titles' => + array ( + 0 => 'Yamada-kun to 7-nin no Majo', + 1 => 'Yamada-kun and the Seven Witches', + ), + 'alternate_title' => NULL, + 'slug' => 'yamada-kun-to-7-nin-no-majo', + 'url' => 'https://kitsu.io/manga/yamada-kun-to-7-nin-no-majo', + 'type' => 'manga', + 'image' => 'https://media.kitsu.io/manga/poster_images/11777/small.jpg?1438784325', + 'genres' => + array ( + 0 => 'Comedy', + 1 => 'Ecchi', + 2 => 'Gender Bender', + 3 => 'Romance', + 4 => 'School', + 5 => 'Sports', + 6 => 'Supernatural', + ), + ), + 'reading_status' => 'current', + 'notes' => '', + 'rereading' => false, + 'reread' => 0, + 'user_rating' => 9.0, + ), + 3 => + array ( + 'id' => '15312827', + 'mal_id' => '78523', + 'chapters' => + array ( + 'read' => 68, + 'total' => '-', + ), + 'volumes' => + array ( + 'read' => '-', + 'total' => '-', + ), + 'manga' => + array ( + 'id' => '27175', + 'titles' => + array ( + 0 => 'ReLIFE', + ), + 'alternate_title' => NULL, + 'slug' => 'relife', + 'url' => 'https://kitsu.io/manga/relife', + 'type' => 'manga', + 'image' => 'https://media.kitsu.io/manga/poster_images/27175/small.jpg?1464379411', + 'genres' => + array ( + 0 => 'Romance', + 1 => 'School', + 2 => 'Slice of Life', + ), + ), + 'reading_status' => 'current', + 'notes' => '', + 'rereading' => false, + 'reread' => 0, + 'user_rating' => '-', + ), + 4 => + array ( + 'id' => '15084769', + 'mal_id' => '60815', + 'chapters' => + array ( + 'read' => 43, + 'total' => '-', + ), + 'volumes' => + array ( + 'read' => '-', + 'total' => '-', + ), + 'manga' => + array ( + 'id' => '25491', + 'titles' => + array ( + 0 => 'Joshikausei', + ), + 'alternate_title' => NULL, + 'slug' => 'joshikausei', + 'url' => 'https://kitsu.io/manga/joshikausei', + 'type' => 'manga', + 'image' => 'https://media.kitsu.io/manga/poster_images/25491/small.jpg?1434305043', + 'genres' => + array ( + 0 => 'Comedy', + 1 => 'School', + 2 => 'Slice of Life', + ), + ), + 'reading_status' => 'current', + 'notes' => '', + 'rereading' => false, + 'reread' => 0, + 'user_rating' => 8.0, + ), +); diff --git a/tests/API/Kitsu/Transformer/__snapshots__/MangaTransformerTest__testTransform__1.php b/tests/API/Kitsu/Transformer/__snapshots__/MangaTransformerTest__testTransform__1.php new file mode 100644 index 00000000..9699bafe --- /dev/null +++ b/tests/API/Kitsu/Transformer/__snapshots__/MangaTransformerTest__testTransform__1.php @@ -0,0 +1,21 @@ + '20286', + 'title' => 'Bokura wa Minna Kawaisou', + 'en_title' => NULL, + 'jp_title' => 'Bokura wa Minna Kawaisou', + 'cover_image' => 'https://media.kitsu.io/manga/poster_images/20286/small.jpg?1434293999', + 'manga_type' => 'manga', + 'chapter_count' => '-', + 'volume_count' => '-', + 'synopsis' => 'Usa, a high-school student aspiring to begin a bachelor lifestyle, moves into a new apartment only to discover that he not only shares a room with a perverted roommate that has an obsession for underaged girls, but also that another girl, Ritsu, a love-at-first-sight, is living in the same building as well! +(Source: Kirei Cake)', + 'url' => 'https://kitsu.io/manga/bokura-wa-minna-kawaisou', + 'genres' => + array ( + 0 => 'Comedy', + 1 => 'Romance', + 2 => 'School', + 3 => 'Slice of Life', + 4 => 'Thriller', + ), +);