|
<?php |
|
/** |
|
* This is an example Amaka Script using PHP 5.4 syntax |
|
* |
|
* The following examples are meant to illustrate some of the possible |
|
* scenarios involving the use of amaka script to run PHPUnit tests, |
|
* possibly using a file system watcher to support a continuous |
|
* testing support. To further support CT I'm planning to implement a |
|
* SpeetTester interface that should create an optimized test suite |
|
* for PHPUnit using source history data on source code and Test Case |
|
* Prioritization to produce the best subset of all test cases most |
|
* likely to spot a failure. |
|
* |
|
* Th examples below illustrate a streamlined syntax deriving from the |
|
* fact amaka scripts are in fact PHP arrays. |
|
* |
|
* Inside of an amaka script definition, a string element it's always |
|
* the description of the next invocable, this also implies one can |
|
* wrap a description on multiple lines by splitting it over multiple |
|
* array elements as they are simply accumulated until the task which |
|
* they describe is found, e.g. |
|
* |
|
* return ['First task ', 'description', $amaka->task(':task', function($t) { echo $t->getTaskDescription(); })]; |
|
* |
|
* It's also possible to map invocables to an array of invocable names |
|
* to declare dependencies: |
|
* |
|
* return [$amaka->task('Test'), $amaka->task(':build') => ['Test']]; |
|
* |
|
* The global $amaka object provides the 'task', 'file' and 'directory' factory methods |
|
* which will return a prebuilt invocable to use as a shorthand when writing amaka scripts. |
|
* |
|
* The signature of the task method is roughly the following one |
|
* task(string $taskname, array $plugins = [], callable $callback, array $taskArgs = []) |
|
*/ |
|
return [ |
|
'Run the tests provided to check the health of the project', |
|
$amaka->task('Test', function ($t) { |
|
|
|
$t->setConfigurationFile($t->taskArgs('c', 'phpunit.xml')); |
|
$t->taskArgs('testdox') && $t->setArgument('--testdox'); |
|
|
|
}, ['c|config=s' => 'Allow another PHPUnit configuration file to be loaded', |
|
'testdox' => "Enable the `testdox' view format"]), |
|
|
|
'This task is executed everytime a file changes in the "tests" directory using the Watcher plugin' |
|
$amaka->task(':develop', ['Watcher'], function($t, $watcher) { |
|
$watcher->watchDirectory('tests'); |
|
}) => ['Test'], |
|
|
|
'This is a task description, and this tasks does something to build the project', |
|
'using the token replacement and archiver plugins to apply filters to code and create packages', |
|
$amaka->task(':build', ['Archiver', 'TokenReplacement'], function ($t, $ar, $tr) use ($amaka) { |
|
$ar->addDirectory('.') |
|
->exclude('something') |
|
->setFormat('tar.gz') |
|
|
|
$tr->bind('<foo>', 'bar'); |
|
$tr->bind('<version>', 'v1.0.2'); |
|
$tr->bind('<build id>', $amaka->build->getId()); |
|
|
|
$ar->apply($tr); |
|
$ar->save(sprintf('%s-%s.tar.gz', date('Y-m-d'), $amaka->build->getId())); |
|
|
|
}) => ['Test', ':configure'], |
|
|
|
'Interactively ask the user to enter configuration options ', |
|
'or using command line switches', |
|
$amaka->task(':configure', ['TokenReplacement', 'Cli', 'Finder'], function($t, $tr, $cli, $finder) { |
|
$host = $t->taskArgs('host') || $cli->prompt('Database Host (localhost): '); |
|
$database = $t->taskArgs('db') || $cli->prompt('Database name (kentronic): '); |
|
$username = $t->taskArgs('user') || $cli->prompt('Database user username: '); |
|
$adapter = $t->taskArgs('adapter') || $cli->prompt('Database connection driver (mysql): '); |
|
$password = $t->taskArgs('password') || $cli->prompt('Database user password: '); |
|
|
|
$tr->bind('{%db_host%}', $host) |
|
->bind('{%db_user%}', $username) |
|
->bind('{%db_adapter%}', $adapter) |
|
->bind('{%db_password%}', $password) |
|
->bind('{%db_name%}', $database); |
|
|
|
$dist = $finder->files() |
|
->name("*.dist") |
|
->in(__DIR__) |
|
->exclude('vendor') |
|
->apply(function($file) use ($tr, $cli) { |
|
$source = (string) $file; |
|
$cli->print("Writing {$target}"); |
|
$tr->replaceFromInto($source, $target, /** remove suffix */ ".dist"); |
|
}); |
|
}, ['user|u=s', 'password|p=s', 'adapter=s', 'db=s', 'host=s']), |
|
]; |