2020-03-11 23:04:01 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2020-03-12 11:45:11 -04:00
|
|
|
* Hummingbird Anime List Client
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* @package HummingbirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-03-12 11:45:11 -04:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2020-03-11 23:04:01 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-04-10 15:39:39 -04:00
|
|
|
* @version 5
|
2020-03-12 11:45:11 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\Ion\Tests;
|
|
|
|
|
|
|
|
use Aviat\Ion\Enum;
|
|
|
|
use Aviat\Ion\Exception\DoubleRenderException;
|
|
|
|
use Aviat\Ion\Friend;
|
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
|
|
use Aviat\Ion\View;
|
|
|
|
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
public function transform($item)
|
|
|
|
{
|
|
|
|
$out = [];
|
|
|
|
$genre_list = (array) $item;
|
|
|
|
|
|
|
|
foreach($genre_list as $genre)
|
|
|
|
{
|
|
|
|
$out[] = $genre['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestTransformerUntransform extends TestTransformer {
|
|
|
|
public function untransform($item)
|
|
|
|
{
|
|
|
|
return (array)$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public function send(): void
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestView extends View {
|
|
|
|
public function send(): void
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
|
|
|
public function output() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestHtmlView extends HtmlView {
|
|
|
|
protected function output(): void
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestHttpView extends HttpView {
|
|
|
|
protected function output(): void
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestJsonView extends JsonView {
|
|
|
|
public function __destruct() {}
|
|
|
|
|
|
|
|
protected function output(): void
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// AnimeClient Mocks
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
trait MockInjectionTrait {
|
|
|
|
public function __get($key)
|
|
|
|
{
|
|
|
|
return $this->$key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __set($key, $value)
|
|
|
|
{
|
|
|
|
$this->$key = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of mocks.php
|