diff --git a/phpunit.xml b/phpunit.xml
index ea5f2d2a..744a9611 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -5,7 +5,8 @@
bootstrap="tests/bootstrap.php">
- src/Aviat
+ src/Aviat/Ion
+ src/Aviat/AnimeClient
diff --git a/src/Aviat/AnimeClient/Transformer/Hummingbird/AnimeListTransformer.php b/src/Aviat/AnimeClient/Transformer/Hummingbird/AnimeListTransformer.php
index 8508a9b7..e78a292e 100644
--- a/src/Aviat/AnimeClient/Transformer/Hummingbird/AnimeListTransformer.php
+++ b/src/Aviat/AnimeClient/Transformer/Hummingbird/AnimeListTransformer.php
@@ -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' => [
diff --git a/src/Aviat/AnimeClient/Transformer/Hummingbird/MangaListTransformer.php b/src/Aviat/AnimeClient/Transformer/Hummingbird/MangaListTransformer.php
index 100b98c8..c0acab7d 100644
--- a/src/Aviat/AnimeClient/Transformer/Hummingbird/MangaListTransformer.php
+++ b/src/Aviat/AnimeClient/Transformer/Hummingbird/MangaListTransformer.php
@@ -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)
diff --git a/src/Aviat/Ion/Friend.php b/src/Aviat/Ion/Friend.php
index 4fb43143..87004b8d 100644
--- a/src/Aviat/Ion/Friend.php
+++ b/src/Aviat/Ion/Friend.php
@@ -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;
}
diff --git a/src/Aviat/Ion/StaticInstance.php b/src/Aviat/Ion/StaticInstance.php
index b142aefb..6cf5f2ef 100644
--- a/src/Aviat/Ion/StaticInstance.php
+++ b/src/Aviat/Ion/StaticInstance.php
@@ -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
diff --git a/src/Aviat/Ion/StringWrapper.php b/src/Aviat/Ion/StringWrapper.php
new file mode 100644
index 00000000..6460b208
--- /dev/null
+++ b/src/Aviat/Ion/StringWrapper.php
@@ -0,0 +1,20 @@
+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();
}
/**
diff --git a/tests/AnimeClient/Model/AnimeCollectionModelTest.php b/tests/AnimeClient/Model/AnimeCollectionModelTest.php
new file mode 100644
index 00000000..1f7bc228
--- /dev/null
+++ b/tests/AnimeClient/Model/AnimeCollectionModelTest.php
@@ -0,0 +1,56 @@
+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);
+ }
+}
\ No newline at end of file
diff --git a/tests/AnimeClient/Model/AnimeModelTest.php b/tests/AnimeClient/Model/AnimeModelTest.php
new file mode 100644
index 00000000..3875a0df
--- /dev/null
+++ b/tests/AnimeClient/Model/AnimeModelTest.php
@@ -0,0 +1,40 @@
+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");
+ }
+}
\ No newline at end of file
diff --git a/tests/AnimeClient/RouterTest.php b/tests/AnimeClient/RouterTest.php
index 03073999..78ca6c4d 100644
--- a/tests/AnimeClient/RouterTest.php
+++ b/tests/AnimeClient/RouterTest.php
@@ -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'
]
]
],
diff --git a/tests/Ion/FriendTest.php b/tests/Ion/FriendTest.php
index 27d2e770..702ae2ae 100644
--- a/tests/Ion/FriendTest.php
+++ b/tests/Ion/FriendTest.php
@@ -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()
diff --git a/tests/Ion/ViewTest.php b/tests/Ion/ViewTest.php
new file mode 100644
index 00000000..425f564b
--- /dev/null
+++ b/tests/Ion/ViewTest.php
@@ -0,0 +1,61 @@
+ $_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('');
+ $this->assertEquals($same, $this->view);
+ $this->assertEquals('', $this->view->getOutput());
+ }
+
+ public function testAppendOutput()
+ {
+ $this->view->setOutput('');
+ $this->view->appendOutput('
');
+ $this->assertEquals('', $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());
+ }
+}
\ No newline at end of file