From a6649465c322e67f4b722ab958d4172d25a3741a Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 5 Aug 2016 16:20:26 -0400 Subject: [PATCH] Create Robofile to use Robo as a task runner --- .gitignore | 7 +- RoboFile.php | 278 +++++++++++++++++++++++++++ build/phpdox.xml | 5 +- composer.json | 9 +- phpdoc.dist.xml | 6 +- src/Aviat/Ion/Cache/CacheManager.php | 2 + src/Aviat/Ion/ConfigInterface.php | 3 + src/Aviat/Ion/JsonException.php | 3 + 8 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 RoboFile.php diff --git a/.gitignore b/.gitignore index 78031d8..603fd50 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ composer.lock *.sqlite *.db *.sqlite3 -docs/* +docs/ tests/test_data/sessions/* cache.properties build/** @@ -26,4 +26,7 @@ app/config/*.toml phinx.yml .idea/ Caddyfile -build/humbuglog.txt \ No newline at end of file +build/humbuglog.txt +phpdoc/ +tests/test_data/json_write.json +tests/test_data/sessions/ diff --git a/RoboFile.php b/RoboFile.php new file mode 100644 index 0000000..19441e8 --- /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}"); + } + + $task->addToCollection($collection); + } + + /** + * 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/phpdox.xml b/build/phpdox.xml index 0be4b97..73d9693 100644 --- a/build/phpdox.xml +++ b/build/phpdox.xml @@ -9,7 +9,7 @@ - + @@ -99,16 +99,15 @@ + - diff --git a/composer.json b/composer.json index 6d049c0..fc10ec6 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,11 @@ "name": "aviat/ion", "description": "Basic PHP Framework", "license":"MIT", + "autoload": { + "psr-4": { + "": "src/" + } + }, "require": { "aviat/query": "^2.5", "aura/html": "2.*", @@ -12,7 +17,6 @@ "predis/predis": "1.1.*", "psr/http-message": "~1.0", "psr/log": "~1.0", - "yosymfony/toml": "0.3.*", "zendframework/zend-diactoros": "1.3.*" }, "require-dev": { @@ -24,6 +28,7 @@ "phpunit/phpunit": "^5.4", "robmorgan/phinx": "^0.6.4", "humbug/humbug": "~1.0@dev", - "codegyre/robo": "*" + "consolidation/robo": "~1.0@dev", + "henrikbjorn/lurker": "^1.1.0" } } diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml index 194e906..2fa15d4 100644 --- a/phpdoc.dist.xml +++ b/phpdoc.dist.xml @@ -1,11 +1,11 @@ - Hummingbird Anime Client + Ion Framework - docs + phpdoc - docs + phpdoc