From 47b8a83d86efc9d05ab64ddc7e897f57a2143e36 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 19 Apr 2016 14:51:58 -0400 Subject: [PATCH] Update changelog and add additional tests --- CHANGELOG.md | 5 ++- console | 3 +- src/Aviat/AnimeClient/Command/BaseCommand.php | 23 +++++++++++- src/Aviat/AnimeClient/Command/CacheImages.php | 16 -------- src/Aviat/AnimeClient/Command/ClearCache.php | 37 +++++++++++++++++++ tests/AnimeClient/Command/BaseCommandTest.php | 19 ++++++++++ tests/Ion/Cache/Driver/RedisDriver2Test.php | 36 ++++++++++++++++++ tests/Ion/Cache/Driver/RedisDriverTest.php | 7 +++- 8 files changed, 126 insertions(+), 20 deletions(-) create mode 100644 src/Aviat/AnimeClient/Command/ClearCache.php create mode 100644 tests/AnimeClient/Command/BaseCommandTest.php create mode 100644 tests/Ion/Cache/Driver/RedisDriver2Test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e9c5db3..94d2d7f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## Version 3 +* Converted user configuration to toml files * Added a caching layer for api calls, which resets upon updates from the app. -* Removed json file "cache" from the app folder \ No newline at end of file +* Added a bulk thumbnail generator script +* Removed json file "cache" from the app folder + diff --git a/console b/console index be735323..2f87d89d 100755 --- a/console +++ b/console @@ -52,7 +52,8 @@ unset($CONF_DIR); // Start console script // --------------------------------------------------------------------------------------------------------------------- $console = new \ConsoleKit\Console([ - 'cache-images' => '\Aviat\AnimeClient\Command\CacheImages' + 'cache-images' => '\Aviat\AnimeClient\Command\CacheImages', + 'clear-cache' => '\Aviat\AnimeClient\Command\ClearCache', ]); $console->run(); \ No newline at end of file diff --git a/src/Aviat/AnimeClient/Command/BaseCommand.php b/src/Aviat/AnimeClient/Command/BaseCommand.php index f4300431..980ccc22 100644 --- a/src/Aviat/AnimeClient/Command/BaseCommand.php +++ b/src/Aviat/AnimeClient/Command/BaseCommand.php @@ -14,6 +14,8 @@ namespace Aviat\AnimeClient\Command; use Aura\Session\SessionFactory; +use ConsoleKit\Command; +use ConsoleKit\Widgets\Box; use Aviat\Ion\Di\Container; use Aviat\Ion\Cache\CacheManager; @@ -25,9 +27,28 @@ use Aviat\AnimeClient\Model; /** * Base class for console command setup */ -class BaseCommand extends \ConsoleKit\Command { +class BaseCommand extends Command { use \Aviat\Ion\Di\ContainerAware; + /** + * Echo text in a box + * + * @param string $message + * @return void + */ + protected function echoBox($message) + { + echo "\n"; + $box = new Box($this->getConsole(), $message); + $box->write(); + echo "\n"; + } + + /** + * Setup the Di container + * + * @return Container + */ protected function setupContainer() { $CONF_DIR = __DIR__ . '/../../../../app/config/'; diff --git a/src/Aviat/AnimeClient/Command/CacheImages.php b/src/Aviat/AnimeClient/Command/CacheImages.php index 70b4bbb3..599ef928 100644 --- a/src/Aviat/AnimeClient/Command/CacheImages.php +++ b/src/Aviat/AnimeClient/Command/CacheImages.php @@ -13,8 +13,6 @@ namespace Aviat\AnimeClient\Command; -use \ConsoleKit\Widgets\Box; - use Aviat\AnimeClient\Model; /** * Generates thumbnail image cache so that cover images load faster @@ -25,20 +23,6 @@ class CacheImages extends BaseCommand { protected $animeModel; protected $model; - /** - * Echo text in a box - * - * @param string $message - * @return void - */ - protected function echoBox($message) - { - echo "\n"; - $box = new Box($this->getConsole(), $message); - $box->write(); - echo "\n"; - } - /* * Convert manga images * diff --git a/src/Aviat/AnimeClient/Command/ClearCache.php b/src/Aviat/AnimeClient/Command/ClearCache.php new file mode 100644 index 00000000..a319b02e --- /dev/null +++ b/src/Aviat/AnimeClient/Command/ClearCache.php @@ -0,0 +1,37 @@ +setContainer($this->setupContainer()); + $cache = $this->container->get('cache'); + $cache->purge(); + + $this->echoBox('API Cache has been cleared.'); + } +} +// End of ClearCache.php \ No newline at end of file diff --git a/tests/AnimeClient/Command/BaseCommandTest.php b/tests/AnimeClient/Command/BaseCommandTest.php new file mode 100644 index 00000000..46eb6b63 --- /dev/null +++ b/tests/AnimeClient/Command/BaseCommandTest.php @@ -0,0 +1,19 @@ +base = new BaseCommand(new Console()); + $this->friend = new Friend($this->base); + } + + public function testSetupContainer() + { + $container = $this->friend->setupContainer(); + $this->assertInstanceOf('Aviat\Ion\Di\Container', $container); + } +} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/RedisDriver2Test.php b/tests/Ion/Cache/Driver/RedisDriver2Test.php new file mode 100644 index 00000000..4f2ecead --- /dev/null +++ b/tests/Ion/Cache/Driver/RedisDriver2Test.php @@ -0,0 +1,36 @@ +set('config', new Config([ + 'redis' => [ + 'host' => 'localhost', + 'port' => 6379, + 'password' => '', + 'database' => 13, + ] + ])); + $this->driver = new RedisDriver($container); + } + + public function tearDown() + { + parent::tearDown(); + $this->driver->__destruct(); + } +} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/RedisDriverTest.php b/tests/Ion/Cache/Driver/RedisDriverTest.php index 0961e7e1..171a3324 100644 --- a/tests/Ion/Cache/Driver/RedisDriverTest.php +++ b/tests/Ion/Cache/Driver/RedisDriverTest.php @@ -2,7 +2,6 @@ require_once('CacheDriverBase.php'); -use Aviat\Ion\Friend; use Aviat\Ion\Cache\Driver\RedisDriver; class CacheRedisDriverTest extends AnimeClient_TestCase { @@ -15,4 +14,10 @@ class CacheRedisDriverTest extends AnimeClient_TestCase { parent::setUp(); $this->driver = new RedisDriver($this->container); } + + public function tearDown() + { + parent::tearDown(); + $this->driver->__destruct(); + } } \ No newline at end of file