Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
6 changed files with 88 additions and 42 deletions
Showing only changes of commit b444648a3d - Show all commits

View File

@ -42,7 +42,8 @@
"henrikbjorn/lurker": "^1.1.0", "henrikbjorn/lurker": "^1.1.0",
"symfony/var-dumper": "^3.2", "symfony/var-dumper": "^3.2",
"squizlabs/php_codesniffer": "^3.0.0@beta", "squizlabs/php_codesniffer": "^3.0.0@beta",
"phpstan/phpstan": "^0.6.4" "phpstan/phpstan": "^0.6.4",
"spatie/phpunit-snapshot-assertions": "^0.4.1"
}, },
"scripts": { "scripts": {
"build": "vendor/bin/robo build", "build": "vendor/bin/robo build",

View File

@ -22,7 +22,6 @@ use Aviat\Ion\Friend;
use Aviat\Ion\Json; use Aviat\Ion\Json;
class AnimeListTransformerTest extends AnimeClientTestCase { class AnimeListTransformerTest extends AnimeClientTestCase {
protected $dir; protected $dir;
protected $beforeTransform; protected $beforeTransform;
protected $afterTransform; protected $afterTransform;
@ -34,19 +33,14 @@ class AnimeListTransformerTest extends AnimeClientTestCase {
$this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu'; $this->dir = AnimeClientTestCase::TEST_DATA_DIR . '/Kitsu';
$this->beforeTransform = Json::decodeFile("{$this->dir}/animeListItemBeforeTransform.json"); $this->beforeTransform = Json::decodeFile("{$this->dir}/animeListItemBeforeTransform.json");
$this->afterTransform = Json::decodeFile("{$this->dir}/animeListItemAfterTransform.json");
$this->transformer = new AnimeListTransformer(); $this->transformer = new AnimeListTransformer();
} }
public function testTransform() public function testTransform()
{ {
$expected = $this->afterTransform;
$actual = $this->transformer->transform($this->beforeTransform); $actual = $this->transformer->transform($this->beforeTransform);
$this->assertMatchesSnapshot($actual);
// Json::encodeFile("{$this->dir}/animeListItemAfterTransform.json", $actual);
$this->assertEquals($expected, $actual);
} }
public function dataUntransform() public function dataUntransform()
@ -60,19 +54,6 @@ class AnimeListTransformerTest extends AnimeClientTestCase {
'rewatched' => 0, 'rewatched' => 0,
'notes' => 'Very formulaic.', 'notes' => 'Very formulaic.',
'edit' => true 'edit' => true
],
'expected' => [
'id' => 14047981,
'mal_id' => null,
'data' => [
'status' => 'current',
'rating' => 4,
'reconsuming' => false,
'reconsumeCount' => 0,
'notes' => 'Very formulaic.',
'progress' => 38,
'private' => false
]
] ]
], [ ], [
'input' => [ 'input' => [
@ -86,19 +67,6 @@ class AnimeListTransformerTest extends AnimeClientTestCase {
'edit' => 'true', 'edit' => 'true',
'private' => 'On', 'private' => 'On',
'rewatching' => 'On' 'rewatching' => 'On'
],
'expected' => [
'id' => 14047981,
'mal_id' => '12345',
'data' => [
'status' => 'current',
'rating' => 4,
'reconsuming' => true,
'reconsumeCount' => 0,
'notes' => 'Very formulaic.',
'progress' => 38,
'private' => true,
]
] ]
]]; ]];
} }
@ -106,9 +74,9 @@ class AnimeListTransformerTest extends AnimeClientTestCase {
/** /**
* @dataProvider dataUntransform * @dataProvider dataUntransform
*/ */
public function testUntransform($input, $expected) public function testUntransform($input)
{ {
$actual = $this->transformer->untransform($input); $actual = $this->transformer->untransform($input);
$this->assertEquals($expected, $actual); $this->assertMatchesSnapshot($actual);
} }
} }

View File

@ -0,0 +1,45 @@
<?php return array (
'id' => '15839442',
'mal_id' => '33206',
'episodes' =>
array (
'watched' => 0,
'total' => '-',
'length' => NULL,
),
'airing' =>
array (
'status' => 'Currently Airing',
'started' => '2017-01-12',
'ended' => NULL,
),
'anime' =>
array (
'age_rating' => NULL,
'title' => 'Kobayashi-san Chi no Maid Dragon',
'titles' =>
array (
0 => 'Kobayashi-san Chi no Maid Dragon',
1 => 'Miss Kobayashi\'s Dragon Maid',
2 => '小林さんちのメイドラゴン',
),
'slug' => 'kobayashi-san-chi-no-maid-dragon',
'type' => 'TV',
'image' => 'https://media.kitsu.io/anime/poster_images/12243/small.jpg?1481144116',
'genres' =>
array (
0 => 'Comedy',
1 => 'Fantasy',
2 => 'Slice of Life',
),
'streaming_links' =>
array (
),
),
'watching_status' => 'current',
'notes' => NULL,
'rewatching' => false,
'rewatched' => 0,
'user_rating' => '-',
'private' => false,
);

View File

@ -0,0 +1,14 @@
<?php return array (
'id' => 14047981,
'mal_id' => NULL,
'data' =>
array (
'status' => 'current',
'reconsuming' => false,
'reconsumeCount' => 0,
'notes' => 'Very formulaic.',
'progress' => 38,
'private' => false,
'rating' => 4,
),
);

View File

@ -0,0 +1,14 @@
<?php return array (
'id' => 14047981,
'mal_id' => '12345',
'data' =>
array (
'status' => 'current',
'reconsuming' => true,
'reconsumeCount' => 0,
'notes' => 'Very formulaic.',
'progress' => 38,
'private' => true,
'rating' => 4,
),
);

View File

@ -23,6 +23,7 @@ use function Aviat\Ion\_dir;
use Aura\Web\WebFactory; use Aura\Web\WebFactory;
use Aviat\Ion\Json; use Aviat\Ion\Json;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Spatie\Snapshots\MatchesSnapshots;
use Zend\Diactoros\{ use Zend\Diactoros\{
Response as HttpResponse, Response as HttpResponse,
ServerRequestFactory ServerRequestFactory
@ -36,6 +37,9 @@ define('TEST_VIEW_DIR', __DIR__ . '/test_views');
* Base class for TestCases * Base class for TestCases
*/ */
class AnimeClientTestCase extends TestCase { class AnimeClientTestCase extends TestCase {
use MatchesSnapshots;
// Test directory constants // Test directory constants
const ROOT_DIR = ROOT_DIR; const ROOT_DIR = ROOT_DIR;
const SRC_DIR = SRC_DIR; const SRC_DIR = SRC_DIR;