From e0e63cf094c1f2c37722951461039d4c4767c088 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 9 Aug 2016 11:08:45 -0400 Subject: [PATCH] Move Ion namespace into composer dependency --- RoboFile.php | 278 ++++++++++++++++++ build/ion_header_comment.txt | 10 - build/phpunit.xml | 4 - build/update_header_comments.php | 10 - composer.json | 10 +- phpunit.xml | 4 - src/Aviat/Ion/ArrayWrapper.php | 34 --- src/Aviat/Ion/Cache/CacheInterface.php | 48 --- src/Aviat/Ion/Cache/CacheManager.php | 117 -------- .../Ion/Cache/Driver/DriverInterface.php | 51 ---- src/Aviat/Ion/Cache/Driver/DriverTrait.php | 62 ---- src/Aviat/Ion/Cache/Driver/NullDriver.php | 74 ----- src/Aviat/Ion/Cache/Driver/RedisDriver.php | 117 -------- src/Aviat/Ion/Cache/Driver/SQLDriver.php | 119 -------- src/Aviat/Ion/Config.php | 106 ------- src/Aviat/Ion/ConfigInterface.php | 41 --- src/Aviat/Ion/Di/Container.php | 134 --------- src/Aviat/Ion/Di/ContainerAware.php | 49 --- src/Aviat/Ion/Di/ContainerAwareInterface.php | 36 --- src/Aviat/Ion/Di/ContainerInterface.php | 47 --- .../Ion/Di/Exception/ContainerException.php | 21 -- .../Ion/Di/Exception/NotFoundException.php | 22 -- src/Aviat/Ion/Enum.php | 49 --- src/Aviat/Ion/Exception/ConfigException.php | 20 -- src/Aviat/Ion/Friend.php | 129 -------- src/Aviat/Ion/Json.php | 130 -------- src/Aviat/Ion/JsonException.php | 18 -- src/Aviat/Ion/Model.php | 21 -- src/Aviat/Ion/Model/DB.php | 51 ---- src/Aviat/Ion/StaticInstance.php | 63 ---- src/Aviat/Ion/StringWrapper.php | 33 --- .../Ion/Transformer/AbstractTransformer.php | 42 --- .../Ion/Transformer/TransformerInterface.php | 27 -- src/Aviat/Ion/Type/ArrayType.php | 261 ---------------- src/Aviat/Ion/Type/StringType.php | 23 -- src/Aviat/Ion/View.php | 137 --------- src/Aviat/Ion/View/HtmlView.php | 69 ----- src/Aviat/Ion/View/HttpView.php | 91 ------ src/Aviat/Ion/View/JsonView.php | 47 --- tests/Ion/BaseModelTest.php | 12 - tests/Ion/Cache/CacheManagerTest.php | 40 --- tests/Ion/Cache/Driver/CacheDriverBase.php | 43 --- tests/Ion/Cache/Driver/NullDriverTest.php | 17 -- tests/Ion/Cache/Driver/RedisDriver2Test.php | 38 --- tests/Ion/Cache/Driver/RedisDriverTest.php | 29 -- tests/Ion/Cache/Driver/SQLDriverTest.php | 20 -- tests/Ion/ConfigTest.php | 120 -------- tests/Ion/Di/ContainerAwareTest.php | 39 --- tests/Ion/Di/ContainerTest.php | 89 ------ tests/Ion/EnumTest.php | 68 ----- tests/Ion/FriendTest.php | 56 ---- tests/Ion/JsonTest.php | 68 ----- tests/Ion/Model/BaseDBModelTest.php | 12 - .../Transformer/AbstractTransformerTest.php | 89 ------ tests/Ion/Type/ArrayTypeTest.php | 173 ----------- tests/Ion/View/HtmlViewTest.php | 25 -- tests/Ion/View/HttpViewTest.php | 46 --- tests/Ion/View/JsonViewTest.php | 43 --- 58 files changed, 282 insertions(+), 3350 deletions(-) create mode 100644 RoboFile.php delete mode 100644 build/ion_header_comment.txt delete mode 100644 src/Aviat/Ion/ArrayWrapper.php delete mode 100644 src/Aviat/Ion/Cache/CacheInterface.php delete mode 100644 src/Aviat/Ion/Cache/CacheManager.php delete mode 100644 src/Aviat/Ion/Cache/Driver/DriverInterface.php delete mode 100644 src/Aviat/Ion/Cache/Driver/DriverTrait.php delete mode 100644 src/Aviat/Ion/Cache/Driver/NullDriver.php delete mode 100644 src/Aviat/Ion/Cache/Driver/RedisDriver.php delete mode 100644 src/Aviat/Ion/Cache/Driver/SQLDriver.php delete mode 100644 src/Aviat/Ion/Config.php delete mode 100644 src/Aviat/Ion/ConfigInterface.php delete mode 100644 src/Aviat/Ion/Di/Container.php delete mode 100644 src/Aviat/Ion/Di/ContainerAware.php delete mode 100644 src/Aviat/Ion/Di/ContainerAwareInterface.php delete mode 100644 src/Aviat/Ion/Di/ContainerInterface.php delete mode 100644 src/Aviat/Ion/Di/Exception/ContainerException.php delete mode 100644 src/Aviat/Ion/Di/Exception/NotFoundException.php delete mode 100644 src/Aviat/Ion/Enum.php delete mode 100644 src/Aviat/Ion/Exception/ConfigException.php delete mode 100644 src/Aviat/Ion/Friend.php delete mode 100644 src/Aviat/Ion/Json.php delete mode 100644 src/Aviat/Ion/JsonException.php delete mode 100644 src/Aviat/Ion/Model.php delete mode 100644 src/Aviat/Ion/Model/DB.php delete mode 100644 src/Aviat/Ion/StaticInstance.php delete mode 100644 src/Aviat/Ion/StringWrapper.php delete mode 100644 src/Aviat/Ion/Transformer/AbstractTransformer.php delete mode 100644 src/Aviat/Ion/Transformer/TransformerInterface.php delete mode 100644 src/Aviat/Ion/Type/ArrayType.php delete mode 100644 src/Aviat/Ion/Type/StringType.php delete mode 100644 src/Aviat/Ion/View.php delete mode 100644 src/Aviat/Ion/View/HtmlView.php delete mode 100644 src/Aviat/Ion/View/HttpView.php delete mode 100644 src/Aviat/Ion/View/JsonView.php delete mode 100644 tests/Ion/BaseModelTest.php delete mode 100644 tests/Ion/Cache/CacheManagerTest.php delete mode 100644 tests/Ion/Cache/Driver/CacheDriverBase.php delete mode 100644 tests/Ion/Cache/Driver/NullDriverTest.php delete mode 100644 tests/Ion/Cache/Driver/RedisDriver2Test.php delete mode 100644 tests/Ion/Cache/Driver/RedisDriverTest.php delete mode 100644 tests/Ion/Cache/Driver/SQLDriverTest.php delete mode 100644 tests/Ion/ConfigTest.php delete mode 100644 tests/Ion/Di/ContainerAwareTest.php delete mode 100644 tests/Ion/Di/ContainerTest.php delete mode 100644 tests/Ion/EnumTest.php delete mode 100644 tests/Ion/FriendTest.php delete mode 100644 tests/Ion/JsonTest.php delete mode 100644 tests/Ion/Model/BaseDBModelTest.php delete mode 100644 tests/Ion/Transformer/AbstractTransformerTest.php delete mode 100644 tests/Ion/Type/ArrayTypeTest.php delete mode 100644 tests/Ion/View/HtmlViewTest.php delete mode 100644 tests/Ion/View/HttpViewTest.php delete mode 100644 tests/Ion/View/JsonViewTest.php diff --git a/RoboFile.php b/RoboFile.php new file mode 100644 index 00000000..b63ee609 --- /dev/null +++ b/RoboFile.php @@ -0,0 +1,278 @@ +prepare(); + $this->lint(); + $this->phploc(TRUE); + $this->dependencyReport(); + $this->phpcpdReport(); + } + + /** + * Run all tests, generate coverage, generate docs, generate code statistics + */ + public function build() + { + $this->analyze(); + $this->coverage(); + $this->docs(); + } + + /** + * Cleanup temporary files + */ + public function clean() + { + $cleanFiles = [ + 'build/humbug.json', + 'build/humbug-log.txt', + ]; + array_map(function ($file) { + @unlink($file); + }, $cleanFiles); + + $this->_cleanDir($this->taskDirs); + $this->_deleteDir($this->taskDirs); + } + + /** + * Run unit tests and generate coverage reports + */ + public function coverage() + { + $this->taskPhpUnit() + ->configFile('build/phpunit.xml') + ->printed(true) + ->run(); + } + + /** + * Generate documentation with phpdox + */ + public function docs() + { + $cmd_parts = [ + 'cd build', + '../vendor/bin/phpdox', + 'cd ..' + ]; + $this->_run($cmd_parts, ' && '); + } + + /** + * Verify that source files are valid + */ + public function lint() + { + $files = $this->getAllSourceFiles(); + + $chunks = array_chunk($files, 6); + $collection = $this->collection(); + + foreach($chunks as $chunk) + { + $this->parallelLint($collection, $chunk); + } + + $collection->run(); + } + + + /** + * Run mutation tests with humbug + * + * @param bool $stats - if true, generates stats rather than running mutation tests + */ + public function mutate($stats = FALSE) + { + $test_parts = [ + 'vendor/bin/humbug' + ]; + + $stat_parts = [ + 'vendor/bin/humbug', + '--skip-killed=yes', + '-v', + './build/humbug.json' + ]; + + $cmd_parts = ($stats) ? $stat_parts : $test_parts; + $this->_run($cmd_parts); + } + + /** + * Run the phploc tool + * + * @param bool $report - if true, generates reports instead of direct output + */ + public function phploc($report = FALSE) + { + // Command for generating reports + $report_cmd_parts = [ + 'vendor/bin/phploc', + '--log-csv=build/logs/phploc.csv', + '--log-xml=build/logs/phploc.xml', + 'src', + 'tests' + ]; + + // Command for generating direct output + $normal_cmd_parts = [ + 'vendor/bin/phploc', + '--count-tests', + 'src', + 'tests' + ]; + + $cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts; + + $this->_run($cmd_parts); + } + + /** + * Create temporary directories + */ + public function prepare() + { + $this->clean(); + array_map([$this, '_mkdir'], $this->taskDirs); + } + + /** + * Lint php files and run unit tests + */ + public function test() + { + $this->lint(); + $this->taskPHPUnit() + ->configFile('phpunit.xml') + ->printed(true) + ->run(); + } + + /** + * Watches for file updates, and automatically runs appropriate actions + */ + public function watch() + { + $this->taskWatch() + ->monitor('composer.json', function() { + $this->taskComposerUpdate()->run(); + }) + ->monitor('src', function () { + $this->taskExec('test')->run(); + })->run(); + } + + /** + * Create pdepend reports + */ + protected function dependencyReport() + { + $cmd_parts = [ + 'vendor/bin/pdepend', + '--jdepend-xml=build/logs/jdepend.xml', + '--jdepend-chart=build/pdepend/dependencies.svg', + '--overview-pyramid=build/pdepend/overview-pyramid.svg', + 'src' + ]; + $this->_run($cmd_parts); + } + + /** + * Get the total list of source files, including tests + * + * @return array + */ + protected function getAllSourceFiles() + { + $files = array_merge( + glob_recursive('build/*.php'), + glob_recursive('src/*.php'), + glob_recursive('tests/*.php'), + glob('*.php') + ); + + sort($files); + + return $files; + } + + /** + * Run php's linter in one parallel task for the passed chunk + * + * @param Collection $collection + * @param array $chunk + */ + protected function parallelLint($collection, array $chunk) + { + $task = $this->taskParallelExec(); + + foreach($chunk as $file) + { + $task = $task->process("php -l {$file}"); + } + + $collection->add($task); + } + + /** + * Generate copy paste detector report + */ + protected function phpcpdReport() + { + $cmd_parts = [ + 'vendor/bin/phpcpd', + '--log-pmd build/logs/pmd-cpd.xml', + 'src' + ]; + $this->_run($cmd_parts); + } + + /** + * Short cut for joining an array of command arguments + * and then running it + * + * @param array $cmd_parts - command arguments + * @param string $join_on - what to join the command arguments with + */ + protected function _run(array $cmd_parts, $join_on = ' ') + { + $this->_exec(implode($join_on, $cmd_parts)); + } +} \ No newline at end of file diff --git a/build/ion_header_comment.txt b/build/ion_header_comment.txt deleted file mode 100644 index 50a30257..00000000 --- a/build/ion_header_comment.txt +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Ion - * - * Building blocks for web development - * - * @package Ion - * @author Timothy J. Warren - * @copyright Copyright (c) 2015 - 2016 - * @license MIT - */ \ No newline at end of file diff --git a/build/phpunit.xml b/build/phpunit.xml index 3c63f182..0b605295 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -8,14 +8,10 @@ > - ../src/Aviat/Ion ../src/Aviat/AnimeClient - - ../tests/Ion - ../tests/AnimeClient diff --git a/build/update_header_comments.php b/build/update_header_comments.php index 852cf635..a7423f3b 100644 --- a/build/update_header_comments.php +++ b/build/update_header_comments.php @@ -7,10 +7,6 @@ $animeclient_file_patterns = [ 'src/Aviat/AnimeClient/*.php' ]; -$ion_file_patterns = [ - 'src/Aviat/Ion/*.php' -]; - if ( ! function_exists('glob_recursive')) { // Does not support flag GLOB_BRACE @@ -80,10 +76,4 @@ $loose_files = [ ]; replace_files($loose_files, '/animeclient_header_comment.txt'); -foreach ($ion_file_patterns as $glob) -{ - $files = glob_recursive($glob); - replace_files($files, '/ion_header_comment.txt'); -} - echo "Successfully updated headers \n"; \ No newline at end of file diff --git a/composer.json b/composer.json index 0a7b0777..f769e115 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,10 @@ "aura/html": "2.*", "aura/router": "3.*", "aura/session": "2.*", - "aviat4ion/query": "2.5.*", - "container-interop/container-interop": "1.*", - "danielstjules/stringy": "~2.1", + "aviat/ion": "dev-master", "filp/whoops": "2.0.*", "guzzlehttp/guzzle": "6.*", "monolog/monolog": "1.*", - "predis/predis": "1.1.*", "psr/http-message": "~1.0", "psr/log": "~1.0", "yosymfony/toml": "0.3.*", @@ -21,7 +18,6 @@ "maximebf/consolekit": "^1.0" }, "require-dev": { - "codeclimate/php-test-reporter": "dev-master", "pdepend/pdepend": "^2.2", "sebastian/phpcpd": "^2.0", "theseer/phpdox": "0.8.1.1", @@ -29,6 +25,8 @@ "phpmd/phpmd": "^2.4", "phpunit/phpunit": "^5.4", "robmorgan/phinx": "^0.6.4", - "humbug/humbug": "~1.0@dev" + "humbug/humbug": "~1.0@dev", + "consolidation/robo": "~1.0@dev", + "henrikbjorn/lurker": "^1.1.0" } } diff --git a/phpunit.xml b/phpunit.xml index 6f5df955..18ac4012 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,14 +7,10 @@ > - src/Aviat/Ion src/Aviat/AnimeClient - - tests/Ion - tests/AnimeClient diff --git a/src/Aviat/Ion/ArrayWrapper.php b/src/Aviat/Ion/ArrayWrapper.php deleted file mode 100644 index 74ec7da4..00000000 --- a/src/Aviat/Ion/ArrayWrapper.php +++ /dev/null @@ -1,34 +0,0 @@ -get('cache_driver'); - - if (empty($driverConf)) - { - $driverConf = 'NullDriver'; - } - - $driverClass = __NAMESPACE__ . "\\Driver\\{$driverConf}"; - $driver = new $driverClass($config); - - $this->driver = $driver; - } - - /** - * Retrieve a cached value if it exists, otherwise, get the value - * from the passed arguments - * - * @param object $object - object to retrieve fresh value from - * @param string $method - method name to call - * @param [array] $args - the arguments to pass to the retrieval method - * @return mixed - the cached or fresh data - */ - public function get($object, $method, array $args=[]) - { - $hash = $this->generateHashForMethod($object, $method, $args); - - $data = $this->driver->get($hash); - - if (empty($data)) - { - $data = call_user_func_array([$object, $method], $args); - $this->driver->set($hash, $data); - } - - return $data; - } - - /** - * Retrieve a fresh value from the method, and update the cache - * @param object $object - object to retrieve fresh value from - * @param string $method - method name to call - * @param [array] $args - the arguments to pass to the retrieval method - * @return mixed - the fresh data - */ - public function getFresh($object, $method, array $args=[]) - { - $hash = $this->generateHashForMethod($object, $method, $args); - $data = call_user_func_array([$object, $method], $args); - $this->driver->set($hash, $data); - return $data; - } - - /** - * Clear the entire cache - * - * @return void - */ - public function purge() - { - $this->driver->invalidateAll(); - } - - /** - * Generate a hash as a cache key from the current method call - * - * @param object $object - * @param string $method - * @param array $args - * @return string - */ - protected function generateHashForMethod($object, $method, array $args) - { - $classname = get_class($object); - $keyObj = [ - 'class' => $classname, - 'method' => $method, - 'args' => $args, - ]; - $hash = sha1(json_encode($keyObj)); - return $hash; - } -} -// End of CacheManager.php \ No newline at end of file diff --git a/src/Aviat/Ion/Cache/Driver/DriverInterface.php b/src/Aviat/Ion/Cache/Driver/DriverInterface.php deleted file mode 100644 index 2f826c21..00000000 --- a/src/Aviat/Ion/Cache/Driver/DriverInterface.php +++ /dev/null @@ -1,51 +0,0 @@ -data)) - ? $this->data[$key] - : NULL; - } - - /** - * Set a cached value - * - * @param string $key - * @param mixed $value - * @return DriverInterface - */ - public function set($key, $value) - { - $this->data[$key] = $value; - return $this; - } - - /** - * Invalidate a cached value - * - * @param string $key - * @return DriverInterface - */ - public function invalidate($key) - { - unset($this->data[$key]); - return $this; - } - - /** - * Clear the contents of the cache - * - * @return void - */ - public function invalidateAll() - { - $this->data = []; - } -} -// End of NullDriver.php \ No newline at end of file diff --git a/src/Aviat/Ion/Cache/Driver/RedisDriver.php b/src/Aviat/Ion/Cache/Driver/RedisDriver.php deleted file mode 100644 index dc385aa3..00000000 --- a/src/Aviat/Ion/Cache/Driver/RedisDriver.php +++ /dev/null @@ -1,117 +0,0 @@ -get('redis'); - - // If you don't have a redis password set, and you attempt to send an - // empty string, Redis will think you want to authenticate with a password - // that is an empty string. To work around this, empty string passwords - // are considered to be a lack of a password - if (array_key_exists('password', $redisConfig) && $redisConfig['password'] === '') - { - unset($redisConfig['password']); - } - - $this->redis = new Client($redisConfig); - } - - /** - * Disconnect from redis - */ - public function __destruct() - { - $this->redis = null; - } - - /** - * Retrieve a value from the cache backend - * - * @param string $rawKey - * @return mixed - */ - public function get($rawKey) - { - $key = $this->prefix($rawKey); - $serializedData = $this->redis->get($key); - - return $this->unserialize($serializedData); - } - - /** - * Set a cached value - * - * @param string $rawKey - * @param mixed $value - * @return DriverInterface - */ - public function set($rawKey, $value) - { - $key = $this->prefix($rawKey); - $serializedData = $this->serialize($value); - - $this->redis->set($key, $serializedData); - - return $this; - } - - /** - * Invalidate a cached value - * - * @param string $rawKey - * @return DriverInterface - */ - public function invalidate($rawKey) - { - $key = $this->prefix($rawKey); - $this->redis->del($key); - - return $this; - } - - /** - * Clear the contents of the cache - * - * @return void - */ - public function invalidateAll() - { - $this->redis->flushdb(); - } -} -// End of RedisDriver.php \ No newline at end of file diff --git a/src/Aviat/Ion/Cache/Driver/SQLDriver.php b/src/Aviat/Ion/Cache/Driver/SQLDriver.php deleted file mode 100644 index 703128ec..00000000 --- a/src/Aviat/Ion/Cache/Driver/SQLDriver.php +++ /dev/null @@ -1,119 +0,0 @@ -db_config)) - { - throw new ConfigException("Missing '[cache]' section in database config."); - } - - $this->db = \Query($this->db_config['cache']); - } - - /** - * Retrieve a value from the cache backend - * - * @param string $key - * @return mixed - */ - public function get($key) - { - $query = $this->db->select('value') - ->from('cache') - ->where('key', $key) - ->get(); - - $row = $query->fetch(\PDO::FETCH_ASSOC); - - if (empty($row)) - { - return NULL; - } - - $serializedData = $row['value']; - return $this->unserialize($serializedData); - } - - /** - * Set a cached value - * - * @param string $key - * @param mixed $value - * @return DriverInterface - */ - public function set($key, $value) - { - $serializedData = $this->serialize($value); - - $this->db->set([ - 'key' => $key, - 'value' => $serializedData, - ]); - - $this->db->insert('cache'); - - return $this; - } - - /** - * Invalidate a cached value - * - * @param string $key - * @return DriverInterface - */ - public function invalidate($key) - { - $this->db->where('key', $key) - ->delete('cache'); - - return $this; - } - - /** - * Clear the contents of the cache - * - * @return void - */ - public function invalidateAll() - { - $this->db->truncate('cache'); - } -} -// End of SQLDriver.php \ No newline at end of file diff --git a/src/Aviat/Ion/Config.php b/src/Aviat/Ion/Config.php deleted file mode 100644 index c0dea9f0..00000000 --- a/src/Aviat/Ion/Config.php +++ /dev/null @@ -1,106 +0,0 @@ -map = $this->arr($config_array); - } - - /** - * Get a config value - * - * @param array|string $key - * @return mixed - * @throws ConfigException - */ - public function get($key) - { - if (is_array($key)) - { - return $this->map->get_deep_key($key); - } - - return $this->map->get($key); - } - - /** - * Remove a config value - * - * @param string|array $key - * @return void - */ - public function delete($key) - { - if (is_array($key)) - { - $this->map->set_deep_key($key, NULL); - } - else - { - $pos =& $this->map->get($key); - $pos = NULL; - } - } - - /** - * Set a config value - * - * @param integer|string|array $key - * @param mixed $value - * @throws InvalidArgumentException - * @return Config - */ - public function set($key, $value) - { - if (is_array($key)) - { - $this->map->set_deep_key($key, $value); - } - else if (is_scalar($key) && ! empty($key)) - { - $this->map->set($key, $value); - } - else - { - throw new InvalidArgumentException("Key must be integer, string, or array, and cannot be empty"); - } - - return $this; - } -} -// End of config.php \ No newline at end of file diff --git a/src/Aviat/Ion/ConfigInterface.php b/src/Aviat/Ion/ConfigInterface.php deleted file mode 100644 index 9c644bae..00000000 --- a/src/Aviat/Ion/ConfigInterface.php +++ /dev/null @@ -1,41 +0,0 @@ -container = $values; - $this->loggers = []; - } - - /** - * Finds an entry of the container by its identifier and returns it. - * - * @param string $id Identifier of the entry to look for. - * - * @throws NotFoundException No entry was found for this identifier. - * @throws ContainerException Error while retrieving the entry. - * - * @return mixed Entry. - */ - public function get($id) - { - if ( ! is_string($id)) - { - throw new Exception\ContainerException("Id must be a string"); - } - - if ($this->has($id)) - { - return $this->container[$id]; - } - - throw new Exception\NotFoundException("Item '{$id}' does not exist in container."); - } - - /** - * Add a value to the container - * - * @param string $id - * @param mixed $value - * @return ContainerInterface - */ - public function set($id, $value) - { - $this->container[$id] = $value; - return $this; - } - - /** - * Returns true if the container can return an entry for the given identifier. - * Returns false otherwise. - * - * @param string $id Identifier of the entry to look for. - * - * @return boolean - */ - public function has($id) - { - return array_key_exists($id, $this->container); - } - - /** - * Determine whether a logger channel is registered - * @param string $key The logger channel - * @return boolean - */ - public function hasLogger($key = 'default') - { - return array_key_exists($key, $this->loggers); - } - - /** - * Add a logger to the Container - * - * @param LoggerInterface $logger - * @param string $key The logger 'channel' - * @return ContainerInterface - */ - public function setLogger(LoggerInterface $logger, $key = 'default') - { - $this->loggers[$key] = $logger; - return $this; - } - - /** - * Retrieve a logger for the selected channel - * - * @param string $key The logger to retreive - * @return LoggerInterface|null - */ - public function getLogger($key = 'default') - { - return ($this->hasLogger($key)) - ? $this->loggers[$key] - : NULL; - } -} -// End of Container.php \ No newline at end of file diff --git a/src/Aviat/Ion/Di/ContainerAware.php b/src/Aviat/Ion/Di/ContainerAware.php deleted file mode 100644 index 8aaf0168..00000000 --- a/src/Aviat/Ion/Di/ContainerAware.php +++ /dev/null @@ -1,49 +0,0 @@ -container = $container; - return $this; - } - - /** - * Get the container object - * - * @return ContainerInterface - */ - public function getContainer() - { - return $this->container; - } -} -// End of ContainerAware.php \ No newline at end of file diff --git a/src/Aviat/Ion/Di/ContainerAwareInterface.php b/src/Aviat/Ion/Di/ContainerAwareInterface.php deleted file mode 100644 index 64de7b6b..00000000 --- a/src/Aviat/Ion/Di/ContainerAwareInterface.php +++ /dev/null @@ -1,36 +0,0 @@ -getConstants(); - } - - /** - * Verify that a constant value is valid - * @param mixed $key - * @return boolean - */ - protected function isValid($key) - { - $values = array_values($this->getConstList()); - return in_array($key, $values); - } -} -// End of Enum.php \ No newline at end of file diff --git a/src/Aviat/Ion/Exception/ConfigException.php b/src/Aviat/Ion/Exception/ConfigException.php deleted file mode 100644 index ea1d21c3..00000000 --- a/src/Aviat/Ion/Exception/ConfigException.php +++ /dev/null @@ -1,20 +0,0 @@ -_friend_ = $obj; - $this->_reflect_ = new ReflectionClass($obj); - } - - /** - * Retrieve a friend's property - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - if ($this->_reflect_->hasProperty($key)) - { - $property = $this->_get_property($key); - return $property->getValue($this->_friend_); - } - - return NULL; - } - - /** - * Set a friend's property - * - * @param string $key - * @param mixed $value - * @return void - */ - public function __set($key, $value) - { - if ($this->_reflect_->hasProperty($key)) - { - $property = $this->_get_property($key); - $property->setValue($this->_friend_, $value); - } - } - - /** - * Calls a protected or private method on the friend - * - * @param string $method - * @param array $args - * @return mixed - */ - public function __call($method, $args) - { - if ( ! $this->_reflect_->hasMethod($method)) - { - throw new BadMethodCallException("Method '{$method}' does not exist"); - } - - $friendMethod = new ReflectionMethod($this->_friend_, $method); - $friendMethod->setAccessible(TRUE); - return $friendMethod->invokeArgs($this->_friend_, $args); - } - - /** - * Iterates over parent classes to get a ReflectionProperty - * - * @codeCoverageIgnore - * @param string $name - * @return ReflectionProperty|null - */ - private function _get_property($name) - { - try - { - $property = $this->_reflect_->getProperty($name); - $property->setAccessible(TRUE); - return $property; - } - // Return NULL on any exception, so no further logic needed - // in the catch block - catch (\Exception $e) - { - return NULL; - } - } -} -// End of Friend.php \ No newline at end of file diff --git a/src/Aviat/Ion/Json.php b/src/Aviat/Ion/Json.php deleted file mode 100644 index b1581ecc..00000000 --- a/src/Aviat/Ion/Json.php +++ /dev/null @@ -1,130 +0,0 @@ -isJson(); - } - - /** - * Call the json error functions to check for errors encoding/decoding - * - * @throws JsonException - */ - protected static function check_json_error() - { - $constant_map = [ - JSON_ERROR_NONE => 'JSON_ERROR_NONE', - JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH', - JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH', - JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR', - JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX', - JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8', - JSON_ERROR_RECURSION => 'JSON_ERROR_RECURSION', - JSON_ERROR_INF_OR_NAN => 'JSON_ERROR_INF_OR_NAN', - JSON_ERROR_UNSUPPORTED_TYPE => 'JSON_ERROR_UNSUPPORTED_TYPE' - ]; - - $error = json_last_error(); - $message = json_last_error_msg(); - - if (\JSON_ERROR_NONE !== $error) - { - throw new JsonException("{$constant_map[$error]} - {$message}", $error); - } - } -} -// End of JSON.php \ No newline at end of file diff --git a/src/Aviat/Ion/JsonException.php b/src/Aviat/Ion/JsonException.php deleted file mode 100644 index 5be77c4f..00000000 --- a/src/Aviat/Ion/JsonException.php +++ /dev/null @@ -1,18 +0,0 @@ -config = $config; - $this->db_config = (array)$config->get('database'); - } -} -// End of DB.php \ No newline at end of file diff --git a/src/Aviat/Ion/StaticInstance.php b/src/Aviat/Ion/StaticInstance.php deleted file mode 100644 index 7a67b931..00000000 --- a/src/Aviat/Ion/StaticInstance.php +++ /dev/null @@ -1,63 +0,0 @@ - 'array_chunk', - 'pluck' => 'array_column', - 'key_diff' => 'array_diff_key', - 'diff' => 'array_diff', - 'filter' => 'array_filter', - 'flip' => 'array_flip', - 'intersect' => 'array_intersect', - 'keys' => 'array_keys', - 'merge' => 'array_merge', - 'pad' => 'array_pad', - 'product' => 'array_product', - 'random' => 'array_rand', - 'reduce' => 'array_reduce', - 'reverse' => 'array_reverse', - 'sum' => 'array_sum', - 'unique' => 'array_unique', - 'values' => 'array_values', - ]; - - /** - * Native methods that modify the passed in array - * - * @var array - */ - protected $native_in_place_methods = [ - 'shuffle' => 'shuffle', - 'shift' => 'array_shift', - 'unshift' => 'array_unshift', - 'push' => 'array_push', - 'pop' => 'array_pop', - ]; - - /** - * Create an ArrayType wrapper class - * - * @param array $arr - */ - public function __construct(array &$arr) - { - $this->arr =& $arr; - } - - /** - * Call one of the dynamically created methods - * - * @param string $method - * @param array $args - * @return mixed - * @throws \InvalidArgumentException - */ - public function __call($method, $args) - { - // Simple mapping for the majority of methods - if (array_key_exists($method, $this->native_methods)) - { - $func = $this->native_methods[$method]; - // Set the current array as the first argument of the method - array_unshift($args, $this->arr); - return call_user_func_array($func, $args); - } - - // Mapping for in-place methods - if (array_key_exists($method, $this->native_in_place_methods)) - { - $func = $this->native_in_place_methods[$method]; - $func($this->arr); - return $this->arr; - } - - throw new \InvalidArgumentException("Method '{$method}' does not exist"); - } - - /** - * Does the passed key exist in the current array? - * - * @param string $key - * @return bool - */ - public function has_key($key) - { - return array_key_exists($key, $this->arr); - } - - /** - * Fill an array with the specified value - * - * @param int $start_index - * @param int $num - * @param mixed $value - * @return array - */ - public function fill($start_index, $num, $value) - { - return array_fill($start_index, $num, $value); - } - - /** - * Call a callback on each item of the array - * - * @param callable $callback - * @return array - */ - public function map(callable $callback) - { - return array_map($callback, $this->arr); - } - - /** - * Find an array key by its associated value - * - * @param mixed $value - * @param bool $strict - * @return false|integer|string - */ - public function search($value, $strict = FALSE) - { - return array_search($value, $this->arr, $strict); - } - - /** - * Determine if the array has the passed value - * - * @param mixed $value - * @param bool $strict - * @return bool - */ - public function has($value, $strict = FALSE) - { - return in_array($value, $this->arr, $strict); - } - - /** - * Return the array, or a key - * - * @param string|integer|null $key - * @return mixed - */ - public function &get($key = NULL) - { - $value = NULL; - if (is_null($key)) - { - $value =& $this->arr; - } - else - { - if ($this->has_key($key)) - { - $value =& $this->arr[$key]; - } - } - - return $value; - } - - /** - * Set a key on the array - * - * @param mixed $key - * @param mixed $value - * @return ArrayType - */ - public function set($key, $value) - { - $this->arr[$key] = $value; - return $this; - } - - /** - * Return a reference to the value of an arbitrary key on the array - * - * @param array $key - * @return mixed - */ - public function &get_deep_key(array $key) - { - $pos =& $this->arr; - - foreach ($key as $level) - { - if (empty($pos) || ! is_array($pos)) - { - // Directly returning a NULL value here will - // result in a reference error. This isn't - // excess code, just what's required for this - // unique situation. - $pos = NULL; - return $pos; - } - $pos =& $pos[$level]; - } - - return $pos; - } - - /** - * Sets the value of an arbitrarily deep key in the array - * and returns the modified array - * - * @param array $key - * @param mixed $value - * @return array - */ - public function set_deep_key(array $key, $value) - { - $pos =& $this->arr; - - // Iterate through the levels of the array, - // create the levels if they don't exist - foreach ($key as $level) - { - if ( ! is_array($pos) && empty($pos)) - { - $pos = []; - $pos[$level] = []; - } - $pos =& $pos[$level]; - } - - $pos = $value; - - return $this->arr; - } -} -// End of ArrayType.php \ No newline at end of file diff --git a/src/Aviat/Ion/Type/StringType.php b/src/Aviat/Ion/Type/StringType.php deleted file mode 100644 index 02c8cd81..00000000 --- a/src/Aviat/Ion/Type/StringType.php +++ /dev/null @@ -1,23 +0,0 @@ -setContainer($container); - $this->response = $container->get('response'); - $this->redirectResponse = NULL; - } - - /** - * Send output to client - */ - public function __destruct() - { - if ( ! $this->hasRendered) - { - $this->send(); - } - } - - /** - * Return rendered output - * - * @return string - */ - public function __toString() - { - $this->hasRendered = TRUE; - return $this->getOutput(); - } - - /** - * Set the output string - * - * @param string $string - * @return View - */ - public function setOutput($string) - { - $this->response->getBody()->write($string); - - return $this; - } - - /** - * Append additional output - * - * @param string $string - * @return View - */ - public function appendOutput($string) - { - return $this->setOutput($string); - } - - /** - * Get the current output string - * - * @return string - */ - public function getOutput() - { - return $this->response->getBody()->__toString(); - } - - /** - * Send output to client - * - * @return void - */ - abstract public function send(); -} -// End of View.php \ No newline at end of file diff --git a/src/Aviat/Ion/View/HtmlView.php b/src/Aviat/Ion/View/HtmlView.php deleted file mode 100644 index d73cad04..00000000 --- a/src/Aviat/Ion/View/HtmlView.php +++ /dev/null @@ -1,69 +0,0 @@ -helper = $container->get('html-helper'); - } - - /** - * Response mime type - * - * @var string - */ - protected $contentType = 'text/html'; - - /** - * Render a basic html Template - * - * @param string $path - * @param array $data - * @return string - */ - public function render_template($path, $data) - { - $data['helper'] = $this->helper; - $data['escape'] = $this->helper->escape(); - $data['container'] = $this->container; - - ob_start(); - extract($data); - include_once $path; - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } -} -// End of HtmlView.php \ No newline at end of file diff --git a/src/Aviat/Ion/View/HttpView.php b/src/Aviat/Ion/View/HttpView.php deleted file mode 100644 index 7ff97f01..00000000 --- a/src/Aviat/Ion/View/HttpView.php +++ /dev/null @@ -1,91 +0,0 @@ -response->getReasonPhrase($code); - $this->setStatusCode($code); - $this->response->withHeader('Location', $url); - - if (PHP_SAPI !== 'cli') - { - header("HTTP/1.1 ${code} ${message}"); - header("Location: {$url}"); - } - - $this->hasRendered = TRUE; - ob_end_clean(); - } - - /** - * Set the status code of the request - * - * @param int $code - * @return HttpView - */ - public function setStatusCode($code) - { - $this->response = $this->response->withStatus($code) - ->withProtocolVersion('1.1'); - return $this; - } - - /** - * Send output to client - * - * @return void - */ - public function send() - { - $this->hasRendered = TRUE; - $this->output(); - } - - /** - * Send the appropriate response - * - * @codeCoverageIgnore - * @return void - */ - protected function output() - { - $this->response->withHeader('Content-type', "{$this->contentType};charset=utf-8") - ->withHeader('Content-Security-Policy', "script-src 'self'") - ->withHeader('X-Content-Type-Options', 'nosniff') - ->withHeader('X-XSS-Protection', '1;mode=block') - ->withHeader('X-Frame-Options', 'SAMEORIGIN'); - - $sender = new SapiEmitter($this->response); - $sender->emit($this->response); - } - -} \ No newline at end of file diff --git a/src/Aviat/Ion/View/JsonView.php b/src/Aviat/Ion/View/JsonView.php deleted file mode 100644 index a65dd558..00000000 --- a/src/Aviat/Ion/View/JsonView.php +++ /dev/null @@ -1,47 +0,0 @@ -assertTrue(is_object($baseModel)); - } -} \ No newline at end of file diff --git a/tests/Ion/Cache/CacheManagerTest.php b/tests/Ion/Cache/CacheManagerTest.php deleted file mode 100644 index 7d88dcc1..00000000 --- a/tests/Ion/Cache/CacheManagerTest.php +++ /dev/null @@ -1,40 +0,0 @@ -cache = new CacheManager($this->container->get('config'), $this->container); - $this->friend = new Friend($this->cache); - } - - public function testGet() - { - $this->cachedTime = $this->cache->get($this, 'time'); - $this->assertEquals($this->cache->get($this, 'time'), $this->cachedTime); - } - - public function testGetFresh() - { - $this->assertNotEquals($this->cache->getFresh($this, 'time'), $this->cachedTime); - } - - public function testPurge() - { - $this->cachedTime = $this->cache->get($this, 'time'); - $key = $this->friend->generateHashForMethod($this, 'time', []); - $this->cache->purge(); - $this->assertEmpty($this->friend->driver->get($key)); - } -} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/CacheDriverBase.php b/tests/Ion/Cache/Driver/CacheDriverBase.php deleted file mode 100644 index d1e333aa..00000000 --- a/tests/Ion/Cache/Driver/CacheDriverBase.php +++ /dev/null @@ -1,43 +0,0 @@ - [ - 'baz' => 'foobar' - ] - ]; - - protected $bar = 'secondvalue'; - - public function testHasCacheDriver() - { - $this->assertTrue((bool) $this->driver); - } - - public function testDriverGetSet() - { - $this->driver->set('foo', $this->foo); - $this->driver->set('bar', 'baz'); - $this->assertEquals($this->driver->get('foo'), $this->foo); - $this->assertEquals($this->driver->get('bar'), 'baz'); - } - - public function testInvalidate() - { - $this->driver->set('foo', $this->foo); - $this->driver->invalidate('foo'); - $this->assertEmpty($this->driver->get('foo')); - } - - public function testInvalidateAll() - { - $this->driver->set('foo', $this->foo); - $this->driver->set('bar', $this->bar); - - $this->driver->invalidateAll(); - - $this->assertEmpty($this->driver->get('foo')); - $this->assertEmpty($this->driver->get('bar')); - } -} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/NullDriverTest.php b/tests/Ion/Cache/Driver/NullDriverTest.php deleted file mode 100644 index df6606d4..00000000 --- a/tests/Ion/Cache/Driver/NullDriverTest.php +++ /dev/null @@ -1,17 +0,0 @@ -driver = new NullDriver($this->container->get('config')); - } -} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/RedisDriver2Test.php b/tests/Ion/Cache/Driver/RedisDriver2Test.php deleted file mode 100644 index 62f5482d..00000000 --- a/tests/Ion/Cache/Driver/RedisDriver2Test.php +++ /dev/null @@ -1,38 +0,0 @@ - [ - 'host' => (array_key_exists('REDIS_HOST', $_ENV)) ? $_ENV['REDIS_HOST'] : 'localhost', - 'port' => 6379, - 'password' => '', - 'database' => 13, - ] - ]); - $this->driver = new RedisDriver($config); - } - - public function tearDown() - { - parent::tearDown(); - - if ( ! is_null($this->driver)) - { - $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 deleted file mode 100644 index ed1209f5..00000000 --- a/tests/Ion/Cache/Driver/RedisDriverTest.php +++ /dev/null @@ -1,29 +0,0 @@ -driver = new RedisDriver($this->container->get('config')); - } - - public function tearDown() - { - parent::tearDown(); - - if ( ! is_null($this->driver)) - { - $this->driver->__destruct(); - } - - } -} \ No newline at end of file diff --git a/tests/Ion/Cache/Driver/SQLDriverTest.php b/tests/Ion/Cache/Driver/SQLDriverTest.php deleted file mode 100644 index 4cd98659..00000000 --- a/tests/Ion/Cache/Driver/SQLDriverTest.php +++ /dev/null @@ -1,20 +0,0 @@ -driver = new SQLDriver($this->container->get('config')); - $friend = new Friend($this->driver); - $friend->db->query('CREATE TABLE IF NOT EXISTS "cache" ("key" TEXT NULL, "value" TEXT NULL, PRIMARY KEY ("key"))'); - } -} \ No newline at end of file diff --git a/tests/Ion/ConfigTest.php b/tests/Ion/ConfigTest.php deleted file mode 100644 index ca716cf8..00000000 --- a/tests/Ion/ConfigTest.php +++ /dev/null @@ -1,120 +0,0 @@ -config = new Config([ - 'foo' => 'bar', - 'asset_path' => '/assets', - 'bar' => 'baz' - ]); - } - - public function testConfigGet() - { - $this->assertEquals('bar', $this->config->get('foo')); - $this->assertEquals('baz', $this->config->get('bar')); - $this->assertNull($this->config->get('baz')); - $this->assertNull($this->config->get(['apple', 'sauce', 'is'])); - } - - public function testConfigSet() - { - $ret = $this->config->set('foo', 'foobar'); - $this->assertInstanceOf('Aviat\Ion\Config', $ret); - $this->assertEquals('foobar', $this->config->get('foo')); - - $this->config->set(['apple', 'sauce', 'is'], 'great'); - $apple = $this->config->get('apple'); - $this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly"); - - $this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed."); - - } - - public function testConfigBadSet() - { - $this->setExpectedException('InvalidArgumentException'); - $this->config->set(NULL, FALSE); - } - - public function dataConfigDelete() - { - return [ - 'top level delete' => [ - 'key' => 'apple', - 'assertKeys' => [ - [ - 'path' => ['apple', 'sauce', 'is'], - 'expected' => NULL - ], - [ - 'path' => ['apple', 'sauce'], - 'expected' => NULL - ], - [ - 'path' => 'apple', - 'expected' => NULL - ] - ] - ], - 'mid level delete' => [ - 'key' => ['apple', 'sauce'], - 'assertKeys' => [ - [ - 'path' => ['apple', 'sauce', 'is'], - 'expected' => NULL - ], - [ - 'path' => ['apple', 'sauce'], - 'expected' => NULL - ], - [ - 'path' => 'apple', - 'expected' => [ - 'sauce' => NULL - ] - ] - ] - ], - 'deep delete' => [ - 'key' => ['apple', 'sauce', 'is'], - 'assertKeys' => [ - [ - 'path' => ['apple', 'sauce', 'is'], - 'expected' => NULL - ], - [ - 'path' => ['apple', 'sauce'], - 'expected' => [ - 'is' => NULL - ] - ] - ] - ] - ]; - } - - /** - * @dataProvider dataConfigDelete - */ - public function testConfigDelete($key, $assertKeys) - { - $config = new Config([]); - $config->set(['apple', 'sauce', 'is'], 'great'); - $config->delete($key); - - foreach($assertKeys as $pair) - { - $this->assertEquals($pair['expected'], $config->get($pair['path'])); - } - } - - public function testGetNonExistentConfigItem() - { - $this->assertNull($this->config->get('foobar')); - } -} \ No newline at end of file diff --git a/tests/Ion/Di/ContainerAwareTest.php b/tests/Ion/Di/ContainerAwareTest.php deleted file mode 100644 index dd506721..00000000 --- a/tests/Ion/Di/ContainerAwareTest.php +++ /dev/null @@ -1,39 +0,0 @@ -container = $container; - } -} - - -class ContainerAwareTest extends AnimeClient_TestCase { - - public function setUp() - { - $this->container = new Container(); - $this->aware = new Aware($this->container); - } - - public function testContainerAwareTrait() - { - // The container was set in setup - // check that the get method returns the same - $this->assertSame($this->container, $this->aware->getContainer()); - - $container2 = new Container([ - 'foo' => 'bar', - 'baz' => 'foobar' - ]); - $this->aware->setContainer($container2); - $this->assertSame($container2, $this->aware->getContainer()); - } -} \ No newline at end of file diff --git a/tests/Ion/Di/ContainerTest.php b/tests/Ion/Di/ContainerTest.php deleted file mode 100644 index bbf22627..00000000 --- a/tests/Ion/Di/ContainerTest.php +++ /dev/null @@ -1,89 +0,0 @@ -container = new Container(); - } - - public function dataGetWithException() - { - return [ - 'Bad index type: number' => [ - 'id' => 42, - 'exception' => 'Aviat\Ion\Di\Exception\ContainerException', - 'message' => 'Id must be a string' - ], - 'Bad index type: array' => [ - 'id' => [], - 'exception' => 'Aviat\Ion\Di\Exception\ContainerException', - 'message' => 'Id must be a string' - ], - 'Non-existent id' => [ - 'id' => 'foo', - 'exception' => 'Aviat\Ion\Di\Exception\NotFoundException', - 'message' => "Item 'foo' does not exist in container." - ] - ]; - } - - /** - * @dataProvider dataGetWithException - */ - public function testGetWithException($id, $exception, $message) - { - try - { - $this->container->get($id); - } - catch(ContainerException $e) - { - $this->assertInstanceOf($exception, $e); - $this->assertEquals($message, $e->getMessage()); - } - } - - public function testGetSet() - { - $container = $this->container->set('foo', function() {}); - - $this->assertInstanceOf('Aviat\Ion\Di\Container', $container); - $this->assertInstanceOf('Aviat\Ion\Di\ContainerInterface', $container); - $this->assertTrue(is_callable($container->get('foo'))); - } - - public function testLoggerMethods() - { - // Does the container have the default logger? - $this->assertFalse($this->container->hasLogger()); - $this->assertFalse($this->container->hasLogger('default')); - - $logger1 = new Logger('default'); - $logger2 = new Logger('testing'); - $logger1->pushHandler(new NullHandler()); - $logger2->pushHandler(new TestHandler()); - - // Set the logger channels - $container = $this->container->setLogger($logger1); - $container2 = $this->container->setLogger($logger2, 'test'); - - $this->assertInstanceOf('Aviat\Ion\Di\ContainerInterface', $container); - $this->assertInstanceOf('Aviat\Ion\Di\Container', $container2); - - $this->assertEquals($logger1, $this->container->getLogger('default')); - $this->assertEquals($logger2, $this->container->getLogger('test')); - $this->assertNull($this->container->getLogger('foo')); - - $this->assertTrue($this->container->hasLogger()); - $this->assertTrue($this->container->hasLogger('default')); - $this->assertTrue($this->container->hasLogger('test')); - } -} \ No newline at end of file diff --git a/tests/Ion/EnumTest.php b/tests/Ion/EnumTest.php deleted file mode 100644 index 5a766b19..00000000 --- a/tests/Ion/EnumTest.php +++ /dev/null @@ -1,68 +0,0 @@ - 'bar', - 'BAR' => 'foo', - 'FOOBAR' => 'baz' - ]; - - public function setUp() - { - parent::setUp(); - $this->enum = new TestEnum(); - } - - public function testStaticGetConstList() - { - $actual = TestEnum::getConstList(); - $this->assertEquals($this->expectedConstList, $actual); - } - - public function testGetConstList() - { - $actual = $this->enum->getConstList(); - $this->assertEquals($this->expectedConstList, $actual); - } - - public function dataIsValid() - { - return [ - 'Valid' => [ - 'value' => 'baz', - 'expected' => TRUE, - 'static' => FALSE - ], - 'ValidStatic' => [ - 'value' => 'baz', - 'expected' => TRUE, - 'static' => TRUE - ], - 'Invalid' => [ - 'value' => 'foobar', - 'expected' => FALSE, - 'static' => FALSE - ], - 'InvalidStatic' => [ - 'value' => 'foobar', - 'expected' => FALSE, - 'static' => TRUE - ] - ]; - } - - /** - * @dataProvider dataIsValid - */ - public function testIsValid($value, $expected, $static) - { - $actual = ($static) - ? TestEnum::isValid($value) - : $this->enum->isValid($value); - - $this->assertEquals($expected, $actual); - } -} \ No newline at end of file diff --git a/tests/Ion/FriendTest.php b/tests/Ion/FriendTest.php deleted file mode 100644 index 1569eb42..00000000 --- a/tests/Ion/FriendTest.php +++ /dev/null @@ -1,56 +0,0 @@ -friend = new Friend($obj); - } - - public function testPrivateMethod() - { - $actual = $this->friend->getPrivate(); - $this->assertEquals(23, $actual); - } - - public function testProtectedMethod() - { - $actual = $this->friend->getProtected(); - $this->assertEquals(4, $actual); - } - - public function testGet() - { - $this->assertEquals(356, $this->friend->protected); - $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() - { - $this->setExpectedException('InvalidArgumentException', 'Friend must be an object'); - - $friend = new Friend('foo'); - } - - public function testBadMethod() - { - $this->setExpectedException('BadMethodCallException', "Method 'foo' does not exist"); - $this->friend->foo(); - } -} \ No newline at end of file diff --git a/tests/Ion/JsonTest.php b/tests/Ion/JsonTest.php deleted file mode 100644 index 44cb4bbe..00000000 --- a/tests/Ion/JsonTest.php +++ /dev/null @@ -1,68 +0,0 @@ - [1, 2, 3, 4] - ]; - $expected = '{"foo":[1,2,3,4]}'; - $this->assertEquals($expected, Json::encode($data)); - } - - public function dataEncodeDecode() - { - return [ - 'set1' => [ - 'data' => [ - 'apple' => [ - 'sauce' => ['foo','bar','baz'] - ] - ], - 'expected_size' => 39, - 'expected_json' => '{"apple":{"sauce":["foo","bar","baz"]}}' - ] - ]; - } - - /** - * @dataProvider dataEncodeDecode - */ - public function testEncodeDecodeFile($data, $expected_size, $expected_json) - { - $target_file = _dir(self::TEST_DATA_DIR, 'json_write.json'); - - $actual_size = Json::encodeFile($target_file, $data); - $actual_json = file_get_contents($target_file); - - $this->assertTrue(Json::isJson($actual_json)); - $this->assertEquals($expected_size, $actual_size); - $this->assertEquals($expected_json, $actual_json); - - $this->assertEquals($data, Json::decodeFile($target_file)); - - unlink($target_file); - } - - public function testDecode() - { - $json = '{"foo":[1,2,3,4]}'; - $expected = [ - 'foo' => [1, 2, 3, 4] - ]; - $this->assertEquals($expected, Json::decode($json)); - $this->assertEquals((object)$expected, Json::decode($json, false)); - - $badJson = '{foo:{1|2}}'; - $this->setExpectedException( - 'Aviat\Ion\JsonException', - 'JSON_ERROR_SYNTAX - Syntax error', - JSON_ERROR_SYNTAX - ); - Json::decode($badJson); - } -} \ No newline at end of file diff --git a/tests/Ion/Model/BaseDBModelTest.php b/tests/Ion/Model/BaseDBModelTest.php deleted file mode 100644 index bdaf1954..00000000 --- a/tests/Ion/Model/BaseDBModelTest.php +++ /dev/null @@ -1,12 +0,0 @@ -container->get('config')); - $this->assertTrue(is_object($baseDBModel)); - } -} \ No newline at end of file diff --git a/tests/Ion/Transformer/AbstractTransformerTest.php b/tests/Ion/Transformer/AbstractTransformerTest.php deleted file mode 100644 index 246658ac..00000000 --- a/tests/Ion/Transformer/AbstractTransformerTest.php +++ /dev/null @@ -1,89 +0,0 @@ -transformer = new TestTransformer(); - } - - public function dataTransformCollection() - { - return [ - 'object' => [ - 'original' => [ - (object)[ - ['name' => 'Comedy'], - ['name' => 'Romance'], - ['name' => 'School'], - ['name' => 'Harem'] - ], - (object)[ - ['name' => 'Action'], - ['name' => 'Comedy'], - ['name' => 'Magic'], - ['name' => 'Fantasy'], - ['name' => 'Mahou Shoujo'] - ], - (object)[ - ['name' => 'Comedy'], - ['name' => 'Sci-Fi'] - ] - ], - 'expected' => [ - ['Comedy', 'Romance', 'School', 'Harem'], - ['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'], - ['Comedy', 'Sci-Fi'] - ] - ], - 'array' => [ - 'original' => [ - [ - ['name' => 'Comedy'], - ['name' => 'Romance'], - ['name' => 'School'], - ['name' => 'Harem'] - ], - [ - ['name' => 'Action'], - ['name' => 'Comedy'], - ['name' => 'Magic'], - ['name' => 'Fantasy'], - ['name' => 'Mahou Shoujo'] - ], - [ - ['name' => 'Comedy'], - ['name' => 'Sci-Fi'] - ] - ], - 'expected' => [ - ['Comedy', 'Romance', 'School', 'Harem'], - ['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'], - ['Comedy', 'Sci-Fi'] - ] - ], - ]; - } - - public function testTransform() - { - $data = $this->dataTransformCollection(); - $original = $data['object']['original'][0]; - $expected = $data['object']['expected'][0]; - - $actual = $this->transformer->transform($original); - $this->assertEquals($expected, $actual); - } - - /** - * @dataProvider dataTransformCollection - */ - public function testTransformCollection($original, $expected) - { - $actual = $this->transformer->transform_collection($original); - $this->assertEquals($expected, $actual); - } -} \ No newline at end of file diff --git a/tests/Ion/Type/ArrayTypeTest.php b/tests/Ion/Type/ArrayTypeTest.php deleted file mode 100644 index e78315ee..00000000 --- a/tests/Ion/Type/ArrayTypeTest.php +++ /dev/null @@ -1,173 +0,0 @@ - 'array_chunk', - 'pluck' => 'array_column', - 'assoc_diff' => 'array_diff_assoc', - 'key_diff' => 'array_diff_key', - 'diff' => 'array_diff', - 'filter' => 'array_filter', - 'flip' => 'array_flip', - 'intersect' => 'array_intersect', - 'keys' => 'array_keys', - 'merge' => 'array_merge', - 'pad' => 'array_pad', - 'random' => 'array_rand', - 'reduce' => 'array_reduce', - ]; - - return [ - 'array_merge' => [ - 'method' => 'merge', - 'array' => [1, 3, 5, 7], - 'args' => [[2, 4, 6, 8]], - 'expected' => [1, 3, 5, 7, 2, 4, 6, 8] - ], - 'array_product' => [ - 'method' => 'product', - 'array' => [1, 2, 3], - 'args' => [], - 'expected' => 6 - ], - 'array_reverse' => [ - 'method' => 'reverse', - 'array' => [1, 2, 3, 4, 5], - 'args' => [], - 'expected' => [5, 4, 3, 2, 1] - ], - 'array_sum' => [ - 'method' => 'sum', - 'array' => [1, 2, 3, 4, 5, 6], - 'args' => [], - 'expected' => 21 - ], - 'array_unique' => [ - 'method' => 'unique', - 'array' => [1, 1, 3, 2, 2, 2, 3, 3, 5], - 'args' => [SORT_REGULAR], - 'expected' => [0 => 1, 2 => 3, 3 => 2, 8 => 5] - ], - 'array_values' => [ - 'method' => 'values', - 'array' => ['foo' => 'bar', 'baz' => 'foobar'], - 'args' => [], - 'expected' => ['bar', 'foobar'] - ] - ]; - } - - /** - * Test the array methods defined for the __Call method - * - * @dataProvider dataCall - */ - public function testCall($method, $array, $args, $expected) - { - $obj = $this->arr($array); - $actual = $obj->__call($method, $args); - $this->assertEquals($expected, $actual); - } - - public function testSet() - { - $obj = $this->arr([]); - $arraytype = $obj->set('foo', 'bar'); - - $this->assertInstanceOf('Aviat\Ion\Type\ArrayType', $arraytype); - $this->assertEquals('bar', $obj->get('foo')); - } - - public function testGet() - { - $array = [1, 2, 3, 4, 5]; - $obj = $this->arr($array); - $this->assertEquals($array, $obj->get()); - $this->assertEquals(1, $obj->get(0)); - $this->assertEquals(5, $obj->get(4)); - } - - public function testGetDeepKey() - { - $arr = [ - 'foo' => 'bar', - 'baz' => [ - 'bar' => 'foobar' - ] - ]; - $obj = $this->arr($arr); - $this->assertEquals('foobar', $obj->get_deep_key(['baz', 'bar'])); - $this->assertNull($obj->get_deep_key(['foo', 'bar', 'baz'])); - } - - public function testMap() - { - $obj = $this->arr([1, 2, 3]); - $actual = $obj->map(function($item) { - return $item * 2; - }); - - $this->assertEquals([2, 4, 6], $actual); - } - - public function testBadCall() - { - $obj = $this->arr([]); - - $this->setExpectedException('InvalidArgumentException', "Method 'foo' does not exist"); - $obj->foo(); - } - - public function testShuffle() - { - $original = [1, 2, 3, 4]; - $test = [1, 2, 3, 4]; - $obj = $this->arr($test); - $actual = $obj->shuffle(); - - //$this->assertNotEquals($actual, $original); - $this->assertTrue(is_array($actual)); - } - - public function testHasKey() - { - $obj = $this->arr([ - 'a' => 'b', - 'z' => 'y' - ]); - $this->assertTrue($obj->has_key('a')); - $this->assertFalse($obj->has_key('b')); - } - - public function testHas() - { - $obj = $this->arr([1, 2, 6, 8, 11]); - $this->assertTrue($obj->has(8)); - $this->assertFalse($obj->has(8745)); - } - - public function testSearch() - { - $obj = $this->arr([1, 2, 5, 7, 47]); - $actual = $obj->search(47); - $this->assertEquals(4, $actual); - } - - public function testFill() - { - $obj = $this->arr([]); - $expected = ['?', '?', '?']; - $actual = $obj->fill(0, 3, '?'); - $this->assertEquals($actual, $expected); - } -} \ No newline at end of file diff --git a/tests/Ion/View/HtmlViewTest.php b/tests/Ion/View/HtmlViewTest.php deleted file mode 100644 index cab5aecf..00000000 --- a/tests/Ion/View/HtmlViewTest.php +++ /dev/null @@ -1,25 +0,0 @@ -view = new TestHtmlView($this->container); - } - - public function testRenderTemplate() - { - $path = _dir(self::TEST_VIEW_DIR, 'test_view.php'); - $expected = 'foo'; - $actual = $this->view->render_template($path, [ - 'var' => 'foo' - ]); - $this->assertEquals($expected, $actual); - } - -} \ No newline at end of file diff --git a/tests/Ion/View/HttpViewTest.php b/tests/Ion/View/HttpViewTest.php deleted file mode 100644 index 0112246d..00000000 --- a/tests/Ion/View/HttpViewTest.php +++ /dev/null @@ -1,46 +0,0 @@ -view = new TestHttpView($this->container); - $this->friend = new Friend($this->view); - } - - public function testGetOutput() - { - $this->friend->setOutput('foo'); - $this->assertEquals('foo', $this->friend->getOutput()); - $this->assertFalse($this->friend->hasRendered); - - $this->assertEquals($this->friend->getOutput(), $this->friend->__toString()); - $this->assertTrue($this->friend->hasRendered); - } - - 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 testSetStatusCode() - { - $view = $this->view->setStatusCode(404); - $this->assertEquals(404, $view->response->getStatusCode()); - } -} \ No newline at end of file diff --git a/tests/Ion/View/JsonViewTest.php b/tests/Ion/View/JsonViewTest.php deleted file mode 100644 index 0c21bb54..00000000 --- a/tests/Ion/View/JsonViewTest.php +++ /dev/null @@ -1,43 +0,0 @@ -view = new TestJsonView($this->container); - $this->friend = new Friend($this->view); - } - - public function testSetOutputJSON() - { - // Extend view class to remove destructor which does output - $view = new TestJsonView($this->container); - - // Json encode non-string - $content = ['foo' => 'bar']; - $expected = json_encode($content); - $view->setOutput($content); - $this->assertEquals($expected, $this->view->getOutput()); - } - - public function testSetOutput() - { - // Directly set string - $view = new TestJsonView($this->container); - $content = '{}'; - $expected = '{}'; - $view->setOutput($content); - $this->assertEquals($expected, $view->getOutput()); - } - - public function testOutput() - { - $this->assertEquals('application/json', $this->friend->contentType); - } -} \ No newline at end of file