Improve some test coverage

This commit is contained in:
Timothy Warren 2015-11-17 16:45:41 -05:00
parent 5d2cad4690
commit 8d1986d13b
10 changed files with 101 additions and 10 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ build/logs/*
build/pdepend/*
build/phpdox/*
cache.properties
tests/test_data/cache/*

View File

@ -140,6 +140,7 @@ class Manga extends API {
* Check the status of the cache and return the appropriate response
*
* @param \GuzzleHttp\Message\Response $response
* @codeCoverageIgnore
* @return array
*/
private function _check_cache($response)

View File

@ -53,4 +53,27 @@ class MenuGeneratorTest extends AnimeClient_TestCase {
];
$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'));
}
}

View File

@ -1,10 +1,4 @@
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Aviat\Ion\Friend;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\AnimeClient\Model\Anime as AnimeModel;

View 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));
}
}
}

View File

@ -22,6 +22,10 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
$session_handler = new TestSessionHandler();
session_set_save_handler($session_handler, TRUE);
self::$session_handler = $session_handler;
// Remove test cache files
$files = glob(_dir(TEST_DATA_DIR, 'cache', '*.json'));
array_map('unlink', $files);
}
public function setUp()
@ -30,7 +34,9 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
$config_array = [
'asset_path' => '//localhost/assets/',
'databaase' => [],
'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'),
'database' => [],
'routing' => [
'asset_path' => '/assets'
],

View File

@ -65,5 +65,4 @@ class EnumTest extends AnimeClient_TestCase {
$this->assertEquals($expected, $actual);
}
}

View File

@ -13,6 +13,7 @@ use Aviat\Ion\View\HttpView;
use Aviat\Ion\View\JsonView;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Model\Manga as MangaModel;
use Aviat\AnimeClient\Model\API as BaseApiModel;
@ -136,7 +137,16 @@ class MockBaseApiModel extends BaseApiModel {
}
class TestAnimeModel extends AnimeModel {
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

File diff suppressed because one or more lines are too long