phpci/PHPCI/Plugin/Atoum.php
2013-10-10 01:01:06 +01:00

69 lines
1.7 KiB
PHP

<?php
namespace PHPCI\Plugin;
use PHPCI\Builder;
use PHPCI\Model\Build;
class Atoum implements \PHPCI\Plugin
{
private $args;
private $config;
private $directory;
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$this->phpci = $phpci;
$this->build = $build;
if (isset($options['executable'])) {
$this->executable = $this->phpci->buildPath . DIRECTORY_SEPARATOR.$options['executable'];
} else {
$this->executable = $this->phpci->findBinary('atoum');
}
if (isset($options['args'])) {
$this->args = $options['args'];
}
if (isset($options['config'])) {
$this->config = $options['config'];
}
if (isset($options['directory'])) {
$this->directory = $options['directory'];
}
}
public function execute()
{
$cmd = $this->executable;
if ($this->args !== null) {
$cmd .= " {$this->args}";
}
if ($this->config !== null) {
$cmd .= " -c '{$this->config}'";
}
if ($this->directory !== null) {
$dirPath = $this->phpci->buildPath . DIRECTORY_SEPARATOR . $this->directory;
$cmd .= " -d '{$dirPath}'";
}
$output = '';
$status = true;
exec($cmd, $output);
if (count(preg_grep("/Success \(/", $output)) == 0) {
$status = false;
$this->phpci->log($output, ' ');
}
if (count($output) == 0) {
$status = false;
$this->phpci->log("No test have been performed!", ' ');
}
return $status;
}
}