HummingBirdAnimeClient/tests/Ion/mocks.php

191 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php declare(strict_types=1);
/**
2020-03-12 11:45:11 -04:00
* Hummingbird Anime List Client
*
2020-03-12 11:45:11 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2023-07-13 11:08:05 -04:00
* PHP version 8.1
*
2023-07-13 11:08:05 -04:00
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2023-07-13 11:08:05 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\Ion\Tests;
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\Ion\Transformer\AbstractTransformer;
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
2022-03-04 12:19:47 -05:00
use Aviat\Ion\{Enum, Friend};
// -----------------------------------------------------------------------------
// Mock the default error handler
// -----------------------------------------------------------------------------
2022-03-04 12:19:47 -05:00
class MockErrorHandler
{
public function addDataTable($name, array $values=[])
{
}
}
// -----------------------------------------------------------------------------
// Ion Mocks
// -----------------------------------------------------------------------------
2022-03-04 12:19:47 -05:00
class TestEnum extends Enum
{
2023-05-19 10:56:23 -04:00
final public const FOO = 'bar';
final public const BAR = 'foo';
final public const FOOBAR = 'baz';
}
2022-03-04 12:19:47 -05:00
class FriendGrandParentTestClass
{
protected $grandParentProtected = 84;
}
2022-03-04 12:19:47 -05:00
class FriendParentTestClass extends FriendGrandParentTestClass
{
protected $parentProtected = 47;
2023-05-19 10:56:23 -04:00
private int $parentPrivate = 654;
}
2022-03-04 12:19:47 -05:00
class FriendTestClass extends FriendParentTestClass
{
protected $protected = 356;
2023-05-19 10:56:23 -04:00
private int $private = 486;
protected function getProtected()
{
return 4;
}
private function getPrivate()
{
return 23;
}
}
2022-03-04 12:19:47 -05:00
class TestTransformer extends AbstractTransformer
{
2021-02-12 13:14:58 -05:00
public function transform(array|object $item): array
{
$out = [];
$genre_list = (array) $item;
2022-03-04 12:19:47 -05:00
foreach ($genre_list as $genre)
{
$out[] = $genre['name'];
}
return $out;
}
}
2022-03-04 12:19:47 -05:00
class TestTransformerUntransform extends TestTransformer
{
public function untransform($item)
{
2022-03-04 12:19:47 -05:00
return (array) $item;
}
}
2022-03-04 12:19:47 -05:00
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;
}
}
2022-03-04 12:19:47 -05:00
class TestHtmlView extends HtmlView
{
protected function output(): void
{
if ($this->hasRendered)
{
throw new DoubleRenderException();
}
$this->hasRendered = TRUE;
}
}
2022-03-04 12:19:47 -05:00
class TestHttpView extends HttpView
{
protected function output(): void
{
if ($this->hasRendered)
{
throw new DoubleRenderException();
}
$this->hasRendered = TRUE;
}
}
2022-03-04 12:19:47 -05:00
class TestJsonView extends JsonView
{
public function __destruct()
{
}
protected function output(): void
{
if ($this->hasRendered)
{
throw new DoubleRenderException();
}
$this->hasRendered = TRUE;
}
}
// -----------------------------------------------------------------------------
// AnimeClient Mocks
// -----------------------------------------------------------------------------
2022-03-04 12:19:47 -05:00
trait MockInjectionTrait
{
public function __get($key)
{
2022-03-04 12:19:47 -05:00
return $this->{$key};
}
public function __set($key, $value)
{
2022-03-04 12:19:47 -05:00
$this->{$key} = $value;
return $this;
}
}
2022-03-04 12:19:47 -05:00
// End of mocks.php