2017-03-24 16:18:02 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-08-04 14:55:37 -04:00
|
|
|
/**
|
2017-03-24 16:18:02 -04:00
|
|
|
* Ion
|
|
|
|
*
|
|
|
|
* Building blocks for web development
|
|
|
|
*
|
|
|
|
* PHP version 7
|
|
|
|
*
|
|
|
|
* @package Ion
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2017 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 2.0.0
|
|
|
|
* @link https://git.timshomepage.net/timw4mail/ion
|
2016-08-04 14:55:37 -04:00
|
|
|
*/
|
|
|
|
|
2016-10-19 13:24:08 -04:00
|
|
|
namespace Aviat\Ion\Tests;
|
|
|
|
|
2016-08-04 14:55:37 -04:00
|
|
|
use Aviat\Ion\Enum;
|
2016-08-26 17:21:50 -04:00
|
|
|
use Aviat\Ion\Exception\DoubleRenderException;
|
2016-08-04 14:55:37 -04:00
|
|
|
use Aviat\Ion\Friend;
|
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
|
|
use Aviat\Ion\View;
|
2016-10-19 13:24:08 -04:00
|
|
|
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
2016-08-04 14:55:37 -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 {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait MockViewOutputTrait {
|
2016-08-26 17:21:50 -04:00
|
|
|
/*protected function output() {
|
2016-08-04 14:55:37 -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);
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:21:50 -04:00
|
|
|
//$friend->output();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public function send()
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestView extends View {
|
2016-08-26 17:21:50 -04:00
|
|
|
public function send()
|
2016-08-04 14:55:37 -04:00
|
|
|
{
|
2016-08-26 17:21:50 -04:00
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
2016-08-26 17:21:50 -04:00
|
|
|
public function output() {}
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestHtmlView extends HtmlView {
|
2016-08-26 17:21:50 -04:00
|
|
|
protected function output()
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestHttpView extends HttpView {
|
2016-08-26 17:21:50 -04:00
|
|
|
protected function output()
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestJsonView extends JsonView {
|
|
|
|
public function __destruct() {}
|
2016-08-26 17:21:50 -04:00
|
|
|
|
|
|
|
protected function output()
|
|
|
|
{
|
|
|
|
if ($this->hasRendered)
|
|
|
|
{
|
|
|
|
throw new DoubleRenderException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->hasRendered = TRUE;
|
|
|
|
}
|
2016-08-04 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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
|