Lots of miscellaneous improvements
This commit is contained in:
parent
e8a9982f9a
commit
7917c39065
@ -5,7 +5,8 @@
|
|||||||
bootstrap="tests/bootstrap.php">
|
bootstrap="tests/bootstrap.php">
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory suffix=".php">src/Aviat</directory>
|
<directory suffix=".php">src/Aviat/Ion</directory>
|
||||||
|
<directory suffix=".php">src/Aviat/AnimeClient</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
@ -29,6 +29,10 @@ class AnimeListTransformer extends AbstractTransformer {
|
|||||||
: '-';
|
: '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$total_episodes = (is_numeric($anime['episode_count']))
|
||||||
|
? $anime['episode_count']
|
||||||
|
: '-';
|
||||||
|
|
||||||
$alternate_title = NULL;
|
$alternate_title = NULL;
|
||||||
if (array_key_exists('alternate_title', $anime))
|
if (array_key_exists('alternate_title', $anime))
|
||||||
{
|
{
|
||||||
@ -46,7 +50,7 @@ class AnimeListTransformer extends AbstractTransformer {
|
|||||||
return [
|
return [
|
||||||
'episodes' => [
|
'episodes' => [
|
||||||
'watched' => $item['episodes_watched'],
|
'watched' => $item['episodes_watched'],
|
||||||
'total' => $anime['episode_count'],
|
'total' => $total_episodes,
|
||||||
'length' => $anime['episode_length'],
|
'length' => $anime['episode_length'],
|
||||||
],
|
],
|
||||||
'airing' => [
|
'airing' => [
|
||||||
|
@ -17,7 +17,7 @@ class MangaListTransformer extends AbstractTransformer {
|
|||||||
$manga =& $item['manga'];
|
$manga =& $item['manga'];
|
||||||
|
|
||||||
$rating = (is_numeric($item['rating']))
|
$rating = (is_numeric($item['rating']))
|
||||||
? 2 * $item['rating']
|
? intval(2 * $item['rating'])
|
||||||
: '-';
|
: '-';
|
||||||
|
|
||||||
$total_chapters = ($manga['chapter_count'] > 0)
|
$total_chapters = ($manga['chapter_count'] > 0)
|
||||||
|
@ -13,8 +13,8 @@ use BadMethodCallException;
|
|||||||
*/
|
*/
|
||||||
class Friend {
|
class Friend {
|
||||||
|
|
||||||
protected $_friend_object_;
|
private $_friend_object_;
|
||||||
protected $_reflection_friend_;
|
private $_reflection_friend_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a friend object
|
* Create a friend object
|
||||||
@ -87,26 +87,19 @@ class Friend {
|
|||||||
/**
|
/**
|
||||||
* Iterates over parent classes to get a ReflectionProperty
|
* Iterates over parent classes to get a ReflectionProperty
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ReflectionProperty|null
|
* @return ReflectionProperty|null
|
||||||
*/
|
*/
|
||||||
protected function _get_property($name)
|
private function _get_property($name)
|
||||||
{
|
{
|
||||||
$class = $this->_reflection_friend_;
|
try
|
||||||
|
|
||||||
while($class)
|
|
||||||
{
|
{
|
||||||
try
|
$property = $this->_reflection_friend_->getProperty($name);
|
||||||
{
|
$property->setAccessible(TRUE);
|
||||||
$property = $class->getProperty($name);
|
return $property;
|
||||||
$property->setAccessible(TRUE);
|
|
||||||
return $property;
|
|
||||||
}
|
|
||||||
catch(\ReflectionException $e) {}
|
|
||||||
|
|
||||||
// Property in a parent class
|
|
||||||
$class = $class->getParentClass();
|
|
||||||
}
|
}
|
||||||
|
catch(\Exception $e) {}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ trait StaticInstance {
|
|||||||
* Call methods protected to allow for
|
* Call methods protected to allow for
|
||||||
* static and instance calling
|
* static and instance calling
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @retun mixed
|
* @retun mixed
|
||||||
|
20
src/Aviat/Ion/StringWrapper.php
Normal file
20
src/Aviat/Ion/StringWrapper.php
Normal 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
|
@ -4,6 +4,8 @@ namespace Aviat\Ion\Transformer;
|
|||||||
|
|
||||||
abstract class AbstractTransformer implements TransformerInterface {
|
abstract class AbstractTransformer implements TransformerInterface {
|
||||||
|
|
||||||
|
use \Aviat\Ion\StringWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutate the data structure
|
* Mutate the data structure
|
||||||
*
|
*
|
||||||
|
@ -7,13 +7,7 @@ use Aviat\Ion\Di\ContainerInterface;
|
|||||||
abstract class View {
|
abstract class View {
|
||||||
|
|
||||||
use Di\ContainerAware;
|
use Di\ContainerAware;
|
||||||
|
use \Aviat\Ion\StringWrapper;
|
||||||
/**
|
|
||||||
* DI Container
|
|
||||||
*
|
|
||||||
* @var ContainerInterface
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP response Object
|
* HTTP response Object
|
||||||
@ -32,9 +26,9 @@ abstract class View {
|
|||||||
/**
|
/**
|
||||||
* String of response to be output
|
* String of response to be output
|
||||||
*
|
*
|
||||||
* @var string
|
* @var S
|
||||||
*/
|
*/
|
||||||
protected $output = '';
|
protected $output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -63,7 +57,8 @@ abstract class View {
|
|||||||
*/
|
*/
|
||||||
public function setOutput($string)
|
public function setOutput($string)
|
||||||
{
|
{
|
||||||
$this->output = $string;
|
$this->output = $this->string($string);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +70,8 @@ abstract class View {
|
|||||||
*/
|
*/
|
||||||
public function appendOutput($string)
|
public function appendOutput($string)
|
||||||
{
|
{
|
||||||
$this->output .= $string;
|
$this->output = $this->string($this->output)->append($string);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +82,7 @@ abstract class View {
|
|||||||
*/
|
*/
|
||||||
public function getOutput()
|
public function getOutput()
|
||||||
{
|
{
|
||||||
return $this->output;
|
return $this->string($this->output)->__toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
56
tests/AnimeClient/Model/AnimeCollectionModelTest.php
Normal file
56
tests/AnimeClient/Model/AnimeCollectionModelTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
40
tests/AnimeClient/Model/AnimeModelTest.php
Normal file
40
tests/AnimeClient/Model/AnimeModelTest.php
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
@ -59,19 +59,21 @@ class RouterTest extends AnimeClient_TestCase {
|
|||||||
$default_config = array(
|
$default_config = array(
|
||||||
'routes' => [
|
'routes' => [
|
||||||
'convention' => [
|
'convention' => [
|
||||||
'default_namespace' => '\\Aviat\\AnimeClient\\Controller'
|
'default_namespace' => '\\Aviat\\AnimeClient\\Controller',
|
||||||
|
'default_controller' => '\\Aviat\\AnimeClient\\Controller\\Anime',
|
||||||
|
'default_method' => 'index'
|
||||||
],
|
],
|
||||||
'common' => [
|
'common' => [
|
||||||
'login_form' => [
|
'login_form' => [
|
||||||
'path' => '/login',
|
'path' => '/login',
|
||||||
'action' => ['login'],
|
'action' => 'login',
|
||||||
'verb' => 'get'
|
'verb' => 'get'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'anime' => [
|
'anime' => [
|
||||||
'watching' => [
|
'watching' => [
|
||||||
'path' => '/anime/watching{/view}',
|
'path' => '/anime/watching{/view}',
|
||||||
'action' => ['anime_list'],
|
'action' => 'anime_list',
|
||||||
'params' => [
|
'params' => [
|
||||||
'type' => 'currently-watching',
|
'type' => 'currently-watching',
|
||||||
],
|
],
|
||||||
@ -83,7 +85,7 @@ class RouterTest extends AnimeClient_TestCase {
|
|||||||
'manga' => [
|
'manga' => [
|
||||||
'plan_to_read' => [
|
'plan_to_read' => [
|
||||||
'path' => '/manga/plan_to_read{/view}',
|
'path' => '/manga/plan_to_read{/view}',
|
||||||
'action' => ['manga_list'],
|
'action' => 'manga_list',
|
||||||
'params' => [
|
'params' => [
|
||||||
'type' => 'Plan to Read',
|
'type' => 'Plan to Read',
|
||||||
],
|
],
|
||||||
@ -173,7 +175,9 @@ class RouterTest extends AnimeClient_TestCase {
|
|||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
'convention' => [
|
'convention' => [
|
||||||
'default_namespace' => '\\Aviat\\AnimeClient\\Controller'
|
'default_namespace' => '\\Aviat\\AnimeClient\\Controller',
|
||||||
|
'default_controller' => '\\Aviat\\AnimeClient\\Controller\\Anime',
|
||||||
|
'default_method' => 'index'
|
||||||
],
|
],
|
||||||
'common' => [
|
'common' => [
|
||||||
'login_form' => [
|
'login_form' => [
|
||||||
@ -226,7 +230,9 @@ class RouterTest extends AnimeClient_TestCase {
|
|||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
'convention' => [
|
'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' => [
|
'routes' => [
|
||||||
'convention' => [
|
'convention' => [
|
||||||
'default_namespace' => '\\Aviat\\Ion\\Controller'
|
'default_namespace' => '\\Aviat\\Ion\\Controller',
|
||||||
|
'default_controller' => '\\Aviat\\Ion\\Controller\\Anime',
|
||||||
|
'default_method' => 'index'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -8,6 +8,7 @@ class GrandParentTestClass {
|
|||||||
|
|
||||||
class ParentTestClass extends GrandParentTestClass {
|
class ParentTestClass extends GrandParentTestClass {
|
||||||
protected $parentProtected = 47;
|
protected $parentProtected = 47;
|
||||||
|
private $parentPrivate = 654;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestClass extends ParentTestClass {
|
class TestClass extends ParentTestClass {
|
||||||
@ -49,15 +50,19 @@ class FriendTest extends AnimeClient_TestCase {
|
|||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
$this->assertEquals(356, $this->friend->protected);
|
$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(47, $this->friend->parentProtected);
|
||||||
$this->assertEquals(84, $this->friend->grandParentProtected);
|
$this->assertEquals(84, $this->friend->grandParentProtected);
|
||||||
|
$this->assertNull($this->friend->parentPrivate); // Can't get a parent's privates
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSet()
|
public function testSet()
|
||||||
{
|
{
|
||||||
$this->friend->private = 123;
|
$this->friend->private = 123;
|
||||||
$this->assertEquals(123, $this->friend->private);
|
$this->assertEquals(123, $this->friend->private);
|
||||||
|
|
||||||
|
$this->friend->foo = 32;
|
||||||
|
$this->assertNull($this->friend->foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBadInvokation()
|
public function testBadInvokation()
|
||||||
|
61
tests/Ion/ViewTest.php
Normal file
61
tests/Ion/ViewTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user