Version 5.1 - All the GraphQL #32
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ build/logs/*
|
|||||||
build/pdepend/*
|
build/pdepend/*
|
||||||
build/phpdox/*
|
build/phpdox/*
|
||||||
cache.properties
|
cache.properties
|
||||||
|
tests/test_data/cache/*
|
@ -140,6 +140,7 @@ class Manga extends API {
|
|||||||
* Check the status of the cache and return the appropriate response
|
* Check the status of the cache and return the appropriate response
|
||||||
*
|
*
|
||||||
* @param \GuzzleHttp\Message\Response $response
|
* @param \GuzzleHttp\Message\Response $response
|
||||||
|
* @codeCoverageIgnore
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function _check_cache($response)
|
private function _check_cache($response)
|
||||||
|
@ -53,4 +53,27 @@ class MenuGeneratorTest extends AnimeClient_TestCase {
|
|||||||
];
|
];
|
||||||
$this->assertEquals($expected, $friend->parse_config($menus));
|
$this->assertEquals($expected, $friend->parse_config($menus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBadConfig()
|
||||||
|
{
|
||||||
|
$menus = [
|
||||||
|
'anime_list' => [
|
||||||
|
'route_prefix' => '/anime',
|
||||||
|
'items' => [
|
||||||
|
'watching' => '/watching',
|
||||||
|
'plan_to_watch' => '/plan_to_watch',
|
||||||
|
'on_hold' => '/on_hold',
|
||||||
|
'dropped' => '/dropped',
|
||||||
|
'completed' => '/completed',
|
||||||
|
'all' => '/all'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$config = $this->container->get('config');
|
||||||
|
$config->set('menus', $menus);
|
||||||
|
$this->container->set('config', $config);
|
||||||
|
$expected = '';
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->generator->generate('manga_list'));
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,10 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use GuzzleHttp\Handler\MockHandler;
|
|
||||||
use GuzzleHttp\HandlerStack;
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
|
||||||
|
|
||||||
use Aviat\Ion\Friend;
|
use Aviat\Ion\Friend;
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
||||||
|
56
tests/AnimeClient/Model/MangaModelTest.php
Normal file
56
tests/AnimeClient/Model/MangaModelTest.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
|
use Aviat\Ion\Friend;
|
||||||
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||||
|
use Aviat\AnimeClient\Hummingbird\Enum\MangaReadingStatus;
|
||||||
|
|
||||||
|
class MangaModelTest extends AnimeClient_TestCase {
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->model = new Friend(new TestMangaModel($this->container));
|
||||||
|
$this->mockDir = __DIR__ . '/../../test_data/manga_list';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testZipperLists()
|
||||||
|
{
|
||||||
|
$raw_data = json_decode(file_get_contents($this->mockDir . '/manga.json'), TRUE);
|
||||||
|
$expected = json_decode(file_get_contents($this->mockDir . '/manga-zippered.json'), TRUE);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->model->zipper_lists($raw_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMapByStatus()
|
||||||
|
{
|
||||||
|
$original = json_decode(file_get_contents($this->mockDir . '/manga-transformed.json'), TRUE);
|
||||||
|
$expected = json_decode(file_get_contents($this->mockDir . '/manga-mapped.json'), TRUE);
|
||||||
|
$actual = $this->model->map_by_status($original);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetListFromApi()
|
||||||
|
{
|
||||||
|
$data = file_get_contents($this->mockDir . '/manga.json');
|
||||||
|
$client = $this->getMockClient(200, [
|
||||||
|
'Content-type' => 'application/json'
|
||||||
|
], $data);
|
||||||
|
$this->model->__set('client', $client);
|
||||||
|
|
||||||
|
$reflect = new ReflectionClass($this->model);
|
||||||
|
$constants = $reflect->getConstants();
|
||||||
|
|
||||||
|
$expected_all = json_decode(file_get_contents($this->mockDir . '/manga-mapped.json'), TRUE);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_all, $this->model->_get_list_from_api());
|
||||||
|
|
||||||
|
foreach($constants as $name => $value)
|
||||||
|
{
|
||||||
|
$key = $reflect->getConstant($name);
|
||||||
|
$this->assertEquals($expected_all[$key], $this->model->_get_list_from_api($key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,10 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
|
|||||||
$session_handler = new TestSessionHandler();
|
$session_handler = new TestSessionHandler();
|
||||||
session_set_save_handler($session_handler, TRUE);
|
session_set_save_handler($session_handler, TRUE);
|
||||||
self::$session_handler = $session_handler;
|
self::$session_handler = $session_handler;
|
||||||
|
|
||||||
|
// Remove test cache files
|
||||||
|
$files = glob(_dir(TEST_DATA_DIR, 'cache', '*.json'));
|
||||||
|
array_map('unlink', $files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
@ -30,7 +34,9 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
$config_array = [
|
$config_array = [
|
||||||
'asset_path' => '//localhost/assets/',
|
'asset_path' => '//localhost/assets/',
|
||||||
'databaase' => [],
|
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
|
||||||
|
'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'),
|
||||||
|
'database' => [],
|
||||||
'routing' => [
|
'routing' => [
|
||||||
'asset_path' => '/assets'
|
'asset_path' => '/assets'
|
||||||
],
|
],
|
||||||
|
@ -65,5 +65,4 @@ class EnumTest extends AnimeClient_TestCase {
|
|||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ use Aviat\Ion\View\HttpView;
|
|||||||
use Aviat\Ion\View\JsonView;
|
use Aviat\Ion\View\JsonView;
|
||||||
|
|
||||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
||||||
|
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||||
use Aviat\AnimeClient\Model\API as BaseApiModel;
|
use Aviat\AnimeClient\Model\API as BaseApiModel;
|
||||||
|
|
||||||
|
|
||||||
@ -136,7 +137,16 @@ class MockBaseApiModel extends BaseApiModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestAnimeModel extends AnimeModel {
|
class TestAnimeModel extends AnimeModel {
|
||||||
|
|
||||||
use MockInjectionTrait;
|
use MockInjectionTrait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestMangaModel extends MangaModel {
|
||||||
|
use MockInjectionTrait;
|
||||||
|
|
||||||
|
private function _check_cache($response)
|
||||||
|
{
|
||||||
|
$file = __DIR__ . '/../../test_data/manga_list/manga-transformed.json';
|
||||||
|
return json_decode(file_get_contents($file), TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
// End of mocks.php
|
// End of mocks.php
|
1
tests/test_data/manga_list/manga-mapped.json
Normal file
1
tests/test_data/manga_list/manga-mapped.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user