Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
13 changed files with 226 additions and 39 deletions
Showing only changes of commit 7917c39065 - Show all commits

View File

@ -5,7 +5,8 @@
bootstrap="tests/bootstrap.php">
<filter>
<whitelist>
<directory suffix=".php">src/Aviat</directory>
<directory suffix=".php">src/Aviat/Ion</directory>
<directory suffix=".php">src/Aviat/AnimeClient</directory>
</whitelist>
</filter>
<testsuites>

View File

@ -29,6 +29,10 @@ class AnimeListTransformer extends AbstractTransformer {
: '-';
}
$total_episodes = (is_numeric($anime['episode_count']))
? $anime['episode_count']
: '-';
$alternate_title = NULL;
if (array_key_exists('alternate_title', $anime))
{
@ -46,7 +50,7 @@ class AnimeListTransformer extends AbstractTransformer {
return [
'episodes' => [
'watched' => $item['episodes_watched'],
'total' => $anime['episode_count'],
'total' => $total_episodes,
'length' => $anime['episode_length'],
],
'airing' => [

View File

@ -17,7 +17,7 @@ class MangaListTransformer extends AbstractTransformer {
$manga =& $item['manga'];
$rating = (is_numeric($item['rating']))
? 2 * $item['rating']
? intval(2 * $item['rating'])
: '-';
$total_chapters = ($manga['chapter_count'] > 0)

View File

@ -13,8 +13,8 @@ use BadMethodCallException;
*/
class Friend {
protected $_friend_object_;
protected $_reflection_friend_;
private $_friend_object_;
private $_reflection_friend_;
/**
* Create a friend object
@ -87,26 +87,19 @@ class Friend {
/**
* Iterates over parent classes to get a ReflectionProperty
*
* @codeCoverageIgnore
* @param string $name
* @return ReflectionProperty|null
*/
protected function _get_property($name)
private function _get_property($name)
{
$class = $this->_reflection_friend_;
while($class)
try
{
try
{
$property = $class->getProperty($name);
$property->setAccessible(TRUE);
return $property;
}
catch(\ReflectionException $e) {}
// Property in a parent class
$class = $class->getParentClass();
$property = $this->_reflection_friend_->getProperty($name);
$property->setAccessible(TRUE);
return $property;
}
catch(\Exception $e) {}
return NULL;
}

View File

@ -18,6 +18,7 @@ trait StaticInstance {
* Call methods protected to allow for
* static and instance calling
*
* @codeCoverageIgnore
* @param string $method
* @param array $args
* @retun mixed

View File

@ -0,0 +1,20 @@
<?php
namespace Aviat\Ion;
use Stringy\Stringy as S;
trait StringWrapper {
/**
* Wrap the String in the Stringy class
*
* @param string $str
* @return Stringy\Stringy
*/
public function string($str)
{
return S::create($str);
}
}
// End of StringWrapper.php

View File

@ -4,6 +4,8 @@ namespace Aviat\Ion\Transformer;
abstract class AbstractTransformer implements TransformerInterface {
use \Aviat\Ion\StringWrapper;
/**
* Mutate the data structure
*

View File

@ -7,13 +7,7 @@ use Aviat\Ion\Di\ContainerInterface;
abstract class View {
use Di\ContainerAware;
/**
* DI Container
*
* @var ContainerInterface
*/
protected $container;
use \Aviat\Ion\StringWrapper;
/**
* HTTP response Object
@ -32,9 +26,9 @@ abstract class View {
/**
* String of response to be output
*
* @var string
* @var S
*/
protected $output = '';
protected $output;
/**
* Constructor
@ -63,7 +57,8 @@ abstract class View {
*/
public function setOutput($string)
{
$this->output = $string;
$this->output = $this->string($string);
return $this;
}
@ -75,7 +70,8 @@ abstract class View {
*/
public function appendOutput($string)
{
$this->output .= $string;
$this->output = $this->string($this->output)->append($string);
return $this;
}
@ -86,7 +82,7 @@ abstract class View {
*/
public function getOutput()
{
return $this->output;
return $this->string($this->output)->__toString();
}
/**

View File

@ -0,0 +1,56 @@
<?php
use Aviat\Ion\Friend;
use Aviat\AnimeClient\Config;
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
class AnimeCollectionModelTest extends AnimeClient_TestCase {
public function setUp()
{
parent::setUp();
$this->container->set('config', new Config([
'database' => [
'collection' => [
'type' => 'sqlite',
'host' => '',
'user' => '',
'pass' => '',
'port' => '',
'name' => 'default',
'database' => '',
'file' => ':memory:',
]
]
]));
$this->config = $this->container->get('config');
$this->collectionModel = new AnimeCollectionModel($this->container);
}
public function testSanity()
{
$friend = new Friend($this->collectionModel);
$this->assertInstanceOf('Aviat\AnimeClient\Model\DB', $this->collectionModel);
$this->assertInstanceOf('Aviat\AnimeClient\Model\Anime', $friend->anime_model);
}
public function testInvalidDatabase()
{
$this->container->set('config', new Config([
'database' => [
'collection' => [
'type' => 'sqlite',
'host' => '',
'user' => '',
'pass' => '',
'port' => '',
'name' => 'default',
'database' => '',
'file' => __FILE__,
]
]
]));
$collectionModel = new Friend(new AnimeCollectionModel($this->container));
$this->assertFalse($collectionModel->valid_database);
}
}

View File

@ -0,0 +1,40 @@
<?php
use Aviat\Ion\Friend;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
class AnimeMock extends AnimeModel {
protected $transformed_data_file = __DIR__ . "/../../test_data/anime_list/anime-completed-transformed.json";
protected function _get_list_from_api($status="all")
{
$data = json_decode(file_get_contents($this->transformed_data_file), TRUE);
return $data;
}
}
class AnimeModelTest extends AnimeClient_TestCase {
public function setUp()
{
parent::setUp();
$this->animeModel = new Friend(new AnimeMock($this->container));
}
protected function _pluck_anime_titles($array)
{
$out = [];
foreach($array as $index => $item)
{
$out[] = $item['anime']['title'];
}
return $out;
}
public function testSortByName()
{
$data = $this->animeModel->_get_list_from_api("completed");
}
}

View File

@ -59,19 +59,21 @@ class RouterTest extends AnimeClient_TestCase {
$default_config = array(
'routes' => [
'convention' => [
'default_namespace' => '\\Aviat\\AnimeClient\\Controller'
'default_namespace' => '\\Aviat\\AnimeClient\\Controller',
'default_controller' => '\\Aviat\\AnimeClient\\Controller\\Anime',
'default_method' => 'index'
],
'common' => [
'login_form' => [
'path' => '/login',
'action' => ['login'],
'action' => 'login',
'verb' => 'get'
],
],
'anime' => [
'watching' => [
'path' => '/anime/watching{/view}',
'action' => ['anime_list'],
'action' => 'anime_list',
'params' => [
'type' => 'currently-watching',
],
@ -83,7 +85,7 @@ class RouterTest extends AnimeClient_TestCase {
'manga' => [
'plan_to_read' => [
'path' => '/manga/plan_to_read{/view}',
'action' => ['manga_list'],
'action' => 'manga_list',
'params' => [
'type' => 'Plan to Read',
],
@ -173,7 +175,9 @@ class RouterTest extends AnimeClient_TestCase {
],
'routes' => [
'convention' => [
'default_namespace' => '\\Aviat\\AnimeClient\\Controller'
'default_namespace' => '\\Aviat\\AnimeClient\\Controller',
'default_controller' => '\\Aviat\\AnimeClient\\Controller\\Anime',
'default_method' => 'index'
],
'common' => [
'login_form' => [
@ -226,7 +230,9 @@ class RouterTest extends AnimeClient_TestCase {
],
'routes' => [
'convention' => [
'default_namespace' => '\\Aviat\\AnimeClient\\Controller'
'default_namespace' => '\\Aviat\\AnimeClient\\Controller',
'default_controller' => '\\Aviat\\AnimeClient\\Controller\\Anime',
'default_method' => 'index'
]
]
],
@ -248,7 +254,9 @@ class RouterTest extends AnimeClient_TestCase {
],
'routes' => [
'convention' => [
'default_namespace' => '\\Aviat\\Ion\\Controller'
'default_namespace' => '\\Aviat\\Ion\\Controller',
'default_controller' => '\\Aviat\\Ion\\Controller\\Anime',
'default_method' => 'index'
]
]
],

View File

@ -8,6 +8,7 @@ class GrandParentTestClass {
class ParentTestClass extends GrandParentTestClass {
protected $parentProtected = 47;
private $parentPrivate = 654;
}
class TestClass extends ParentTestClass {
@ -49,15 +50,19 @@ class FriendTest extends AnimeClient_TestCase {
public function testGet()
{
$this->assertEquals(356, $this->friend->protected);
$this->assertNull($this->friend->foo);
$this->assertNull($this->friend->foo); // Return NULL for non-existend properties
$this->assertEquals(47, $this->friend->parentProtected);
$this->assertEquals(84, $this->friend->grandParentProtected);
$this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates
}
public function testSet()
{
$this->friend->private = 123;
$this->assertEquals(123, $this->friend->private);
$this->friend->foo = 32;
$this->assertNull($this->friend->foo);
}
public function testBadInvokation()

61
tests/Ion/ViewTest.php Normal file
View File

@ -0,0 +1,61 @@
<?php
use Aura\Web\WebFactory;
use Aviat\Ion\Friend;
use Aviat\Ion\View;
use Aviat\Ion\Di\Container;
class TestView extends View {
}
class ViewTest extends AnimeClient_TestCase {
public function setUp()
{
parent::setUp();
$web_factory = new WebFactory([
'_GET' => $_GET,
'_POST' => $_POST,
'_COOKIE' => $_COOKIE,
'_SERVER' => $_SERVER,
'_FILES' => $_FILES
]);
$this->container->set('request', $web_factory->newRequest());
$this->container->set('response', $web_factory->newResponse());
$this->view = new TestView($this->container);
$this->friend = new Friend($this->view);
}
public function testGetOutput()
{
$this->friend->output = 'foo';
$this->assertEquals($this->friend->output, $this->friend->getOutput());
}
public function testSetOutput()
{
$same = $this->view->setOutput('<h1></h1>');
$this->assertEquals($same, $this->view);
$this->assertEquals('<h1></h1>', $this->view->getOutput());
}
public function testAppendOutput()
{
$this->view->setOutput('<h1>');
$this->view->appendOutput('</h1>');
$this->assertEquals('<h1></h1>', $this->view->getOutput());
}
public function testOutput()
{
$this->friend->contentType = 'text/html';
$this->friend->__destruct();
$this->assertEquals($this->friend->response->content->getType(), $this->friend->contentType);
$this->assertEquals($this->friend->response->content->getCharset(), 'utf-8');
$this->assertEquals($this->friend->response->content->get(), $this->friend->getOutput());
}
}