Create Robofile to use Robo as a task runner

This commit is contained in:
Timothy Warren 2016-08-05 16:20:26 -04:00
parent b8507a1ecf
commit a6649465c3
8 changed files with 303 additions and 10 deletions

7
.gitignore vendored
View File

@ -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
build/humbuglog.txt
phpdoc/
tests/test_data/json_write.json
tests/test_data/sessions/

278
RoboFile.php Normal file
View File

@ -0,0 +1,278 @@
<?php
if ( ! function_exists('glob_recursive'))
{
// Does not support flag GLOB_BRACE
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
{
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
}
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
protected $taskDirs = [
'build/api',
'build/coverage',
'build/logs',
'build/pdepend',
'build/phpdox',
];
/**
* Do static analysis tasks
*/
public function analyze()
{
$this->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));
}
}

View File

@ -9,7 +9,7 @@
<bootstrap />
<!-- A phpDox project to process, you can have multiple projects in one config file -->
<project name="Hummingbird Anime Client" source="../src" workdir="phpdox/xml">
<project name="Ion Framework" source="../src" workdir="phpdox/xml">
<!-- @name - The name of the project -->
<!-- @source - The source directory of the application to process -->
<!-- @workdir - The directory to store the xml data files in -->
@ -99,16 +99,15 @@
<!-- PHPUnit Coverage XML -->
<source type="phpunit">
<coverage path="coverage" />
<!-- <coverage path="clover.xml" />-->
<!-- @path - the directory where the xml code coverage report can be found -->
<!--<filter directory="${phpDox.project.source}" />-->
<!-- @directory - path of the phpunit config whitelist filter directory -->
</source>
<!--
<source type="phpunit">
<filter directory="${phpDox.project.source}" />
</source>
-->
</enrich>

View File

@ -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"
}
}

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdoc>
<title>Hummingbird Anime Client</title>
<title>Ion Framework</title>
<parser>
<target>docs</target>
<target>phpdoc</target>
</parser>
<transformer>
<target>docs</target>
<target>phpdoc</target>
</transformer>
<transformations>
<template name="clean" />

View File

@ -21,6 +21,8 @@ use Aviat\Ion\Cache\Driver\DriverInterface;
class CacheManager implements CacheInterface {
/**
* The storage backend adapter
*
* @var DriverInterface
*/
protected $driver;

View File

@ -12,6 +12,9 @@
namespace Aviat\Ion;
/**
* Standard interface for retrieving/setting configuration values
*/
interface ConfigInterface {
/**
* Get a config value

View File

@ -12,6 +12,9 @@
namespace Aviat\Ion;
/**
* Exceptions thrown by the Json class
*/
class JsonException extends \InvalidArgumentException {
}