2015-10-19 12:50:46 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* All the mock classes that extend the classes they are used to test
|
|
|
|
*/
|
|
|
|
|
2017-02-15 16:40:18 -05:00
|
|
|
use Aviat\AnimeClient\Model\{
|
|
|
|
Anime as AnimeModel,
|
|
|
|
API as BaseApiModel,
|
|
|
|
Manga as MangaModel
|
|
|
|
};
|
|
|
|
use Aviat\Ion\{Enum, Friend, Json};
|
2015-10-19 12:50:46 -04:00
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
|
|
use Aviat\Ion\View;
|
2017-02-15 16:40:18 -05:00
|
|
|
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
2015-10-19 12:50:46 -04:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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 {
|
2020-04-13 09:20:05 -04:00
|
|
|
protected int $grandParentProtected = 84;
|
2015-10-19 12:50:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class FriendParentTestClass extends FriendGrandParentTestClass {
|
2020-04-13 09:20:05 -04:00
|
|
|
protected int $parentProtected = 47;
|
|
|
|
private int $parentPrivate = 654;
|
2015-10-19 12:50:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class FriendTestClass extends FriendParentTestClass {
|
2020-04-13 09:20:05 -04:00
|
|
|
protected int $protected = 356;
|
|
|
|
private int $private = 486;
|
2015-10-19 12:50:46 -04:00
|
|
|
|
2020-04-13 09:20:05 -04:00
|
|
|
protected function getProtected(): int
|
2015-10-19 12:50:46 -04:00
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2020-04-13 09:20:05 -04:00
|
|
|
private function getPrivate(): int
|
2015-10-19 12:50:46 -04:00
|
|
|
{
|
|
|
|
return 23;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestTransformer extends AbstractTransformer {
|
2015-10-21 15:43:51 -04:00
|
|
|
|
2020-04-13 09:20:05 -04:00
|
|
|
public function transform($item): array
|
2015-10-19 12:50:46 -04:00
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait MockViewOutputTrait {
|
2018-01-18 16:21:45 -05:00
|
|
|
protected function output(): void {
|
2015-10-19 12:50:46 -04:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:18:52 -04:00
|
|
|
class MockUtil {
|
2020-04-13 09:20:05 -04:00
|
|
|
public function get_cached_image($api_path, $series_slug, $type = "anime"): string
|
2016-07-27 13:18:52 -04:00
|
|
|
{
|
|
|
|
return "/public/images/{$type}/{$series_slug}.jpg";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 11:40:24 -05:00
|
|
|
class TestView extends View {
|
2018-01-18 16:21:45 -05:00
|
|
|
public function send(): void {}
|
|
|
|
protected function output(): void
|
2016-01-08 11:40:24 -05:00
|
|
|
{
|
2016-02-17 10:29:05 -05:00
|
|
|
/*$content =& $this->response->content;
|
2016-01-08 11:40:24 -05:00
|
|
|
$content->set($this->output);
|
|
|
|
$content->setType($this->contentType);
|
2016-02-17 10:29:05 -05:00
|
|
|
$content->setCharset('utf-8');*/
|
2016-01-08 11:40:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 12:50:46 -04:00
|
|
|
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;
|
2020-04-13 09:20:05 -04:00
|
|
|
protected string $base_url = 'https://httpbin.org/';
|
2015-10-19 12:50:46 -04:00
|
|
|
|
2016-10-20 22:09:36 -04:00
|
|
|
protected function _get_list_from_api(string $status): array
|
2016-02-02 21:28:32 -05:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
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';
|
2016-01-07 13:45:43 -05:00
|
|
|
return Json::decodeFile($file);
|
2015-11-17 16:45:41 -05:00
|
|
|
}
|
2015-10-19 12:50:46 -04:00
|
|
|
}
|
|
|
|
// End of mocks.php
|