HummingBirdAnimeClient/tests/mocks.php

152 lines
3.1 KiB
PHP
Raw Normal View History

2015-10-19 12:50:46 -04:00
<?php
/**
* All the mock classes that extend the classes they are used to test
*/
use Aviat\Ion\Enum;
use Aviat\Ion\Friend;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Transformer\AbstractTransformer;
use Aviat\Ion\View;
use Aviat\Ion\View\HtmlView;
use Aviat\Ion\View\HttpView;
use Aviat\Ion\View\JsonView;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
2015-11-17 16:45:41 -05:00
use Aviat\AnimeClient\Model\Manga as MangaModel;
2015-10-19 12:50:46 -04:00
use Aviat\AnimeClient\Model\API as BaseApiModel;
// -----------------------------------------------------------------------------
// Mock the default error handler
// -----------------------------------------------------------------------------
class MockErrorHandler {
public function addDataTable($name, array $values=[]) {}
}
// -----------------------------------------------------------------------------
// Ion Mocks
// -----------------------------------------------------------------------------
class TestEnum extends Enum {
const FOO = 'bar';
const BAR = 'foo';
const FOOBAR = 'baz';
}
class FriendGrandParentTestClass {
protected $grandParentProtected = 84;
}
class FriendParentTestClass extends FriendGrandParentTestClass {
protected $parentProtected = 47;
private $parentPrivate = 654;
}
class FriendTestClass extends FriendParentTestClass {
protected $protected = 356;
private $private = 486;
protected function getProtected()
{
return 4;
}
private function getPrivate()
{
return 23;
}
}
class TestTransformer extends AbstractTransformer {
2015-10-21 15:43:51 -04:00
2015-10-19 12:50:46 -04:00
public function transform($item)
{
$out = [];
$genre_list = (array) $item;
2015-10-21 15:43:51 -04:00
2015-10-19 12:50:46 -04:00
foreach($genre_list as $genre)
{
$out[] = $genre['name'];
}
2015-10-21 15:43:51 -04:00
2015-10-19 12:50:46 -04:00
return $out;
}
}
class TestView extends View {}
trait MockViewOutputTrait {
protected function output() {
$reflect = new ReflectionClass($this);
$properties = $reflect->getProperties();
$props = [];
foreach($properties as $reflectProp)
{
$reflectProp->setAccessible(TRUE);
$props[$reflectProp->getName()] = $reflectProp->getValue($this);
}
$view = new TestView($this->container);
$friend = new Friend($view);
foreach($props as $name => $val)
{
$friend->__set($name, $val);
}
$friend->output();
}
}
class TestHtmlView extends HtmlView {
use MockViewOutputTrait;
}
class TestHttpView extends HttpView {
use MockViewOutputTrait;
}
class TestJsonView extends JsonView {
public function __destruct() {}
}
// -----------------------------------------------------------------------------
// AnimeClient Mocks
// -----------------------------------------------------------------------------
2015-10-21 15:43:51 -04:00
trait MockInjectionTrait {
2015-10-19 12:50:46 -04:00
public function __get($key)
{
return $this->$key;
}
2015-10-21 15:43:51 -04:00
2015-10-19 12:50:46 -04:00
public function __set($key, $value)
{
$this->$key = $value;
return $this;
}
}
2015-10-21 15:43:51 -04:00
class MockBaseApiModel extends BaseApiModel {
2015-10-19 12:50:46 -04:00
2015-10-21 15:43:51 -04:00
use MockInjectionTrait;
protected $base_url = 'https://httpbin.org/';
2015-10-19 12:50:46 -04:00
2015-10-21 15:43:51 -04:00
}
2015-10-19 12:50:46 -04:00
2015-10-21 15:43:51 -04:00
class TestAnimeModel extends AnimeModel {
2015-11-17 16:45:41 -05:00
use MockInjectionTrait;
}
2015-10-21 15:43:51 -04:00
2015-11-17 16:45:41 -05:00
class TestMangaModel extends MangaModel {
2015-10-21 15:43:51 -04:00
use MockInjectionTrait;
2015-11-17 16:45:41 -05:00
2015-11-18 10:31:42 -05:00
protected function _check_cache($response)
2015-11-17 16:45:41 -05:00
{
2015-11-18 10:31:42 -05:00
$file = __DIR__ . '/test_data/manga_list/manga-transformed.json';
2015-11-17 16:45:41 -05:00
return json_decode(file_get_contents($file), TRUE);
}
2015-10-19 12:50:46 -04:00
}
// End of mocks.php