2013-06-19 11:29:52 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2013-06-19 11:29:52 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Builder;
|
|
|
|
use PHPCensor\Model\Build;
|
|
|
|
use PHPCensor\Plugin;
|
2013-10-10 02:01:06 +02:00
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Atoum plugin, runs Atoum tests within a project.
|
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
class Atoum extends Plugin
|
2013-06-19 11:29:52 +02:00
|
|
|
{
|
2017-03-04 16:39:56 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
protected $executable;
|
2017-03-04 16:39:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
protected $args;
|
2017-03-04 16:39:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
protected $config;
|
2017-03-04 16:39:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
protected $directory;
|
2013-06-19 11:29:52 +02:00
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'atoum';
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
2016-07-11 18:00:04 +02:00
|
|
|
* {@inheritdoc}
|
2014-12-08 12:25:33 +01:00
|
|
|
*/
|
2016-07-22 09:05:34 +02:00
|
|
|
public function __construct(Builder $builder, Build $build, array $options = [])
|
2013-06-19 11:29:52 +02:00
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
parent::__construct($builder, $build, $options);
|
2013-06-19 11:29:52 +02:00
|
|
|
|
|
|
|
if (isset($options['executable'])) {
|
2018-03-08 04:31:31 +01:00
|
|
|
$this->executable = $this->builder->buildPath . '/' . $options['executable'];
|
2013-08-02 12:12:17 +02:00
|
|
|
} else {
|
2017-07-19 05:26:51 +02:00
|
|
|
$this->executable = $this->findBinary('atoum');
|
2013-06-19 11:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['args'])) {
|
|
|
|
$this->args = $options['args'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['config'])) {
|
|
|
|
$this->config = $options['config'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['directory'])) {
|
|
|
|
$this->directory = $options['directory'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Run the Atoum plugin.
|
2017-11-05 15:48:36 +01:00
|
|
|
*
|
2014-12-08 12:25:33 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2013-06-19 11:29:52 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2013-08-02 12:02:44 +02:00
|
|
|
$cmd = $this->executable;
|
2013-06-19 11:29:52 +02:00
|
|
|
|
|
|
|
if ($this->args !== null) {
|
|
|
|
$cmd .= " {$this->args}";
|
|
|
|
}
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-06-19 11:29:52 +02:00
|
|
|
if ($this->config !== null) {
|
|
|
|
$cmd .= " -c '{$this->config}'";
|
|
|
|
}
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-06-19 11:29:52 +02:00
|
|
|
if ($this->directory !== null) {
|
2018-03-08 04:31:31 +01:00
|
|
|
$dirPath = $this->builder->buildPath . '/' . $this->directory;
|
2013-08-02 12:02:44 +02:00
|
|
|
$cmd .= " -d '{$dirPath}'";
|
2013-06-19 11:29:52 +02:00
|
|
|
}
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
chdir($this->builder->buildPath);
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-08-02 12:02:44 +02:00
|
|
|
$output = '';
|
|
|
|
$status = true;
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-08-02 12:02:44 +02:00
|
|
|
exec($cmd, $output);
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
if (count(preg_grep("/Success \(/", $output)) == 0) {
|
2013-08-02 12:02:44 +02:00
|
|
|
$status = false;
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->builder->log($output);
|
2013-08-02 12:02:44 +02:00
|
|
|
}
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-08-23 18:12:42 +02:00
|
|
|
if (count($output) == 0) {
|
|
|
|
$status = false;
|
2017-02-07 13:05:44 +01:00
|
|
|
$this->builder->log('No tests have been performed.');
|
2013-08-23 18:12:42 +02:00
|
|
|
}
|
2017-03-04 16:39:56 +01:00
|
|
|
|
2013-08-02 12:02:44 +02:00
|
|
|
return $status;
|
2013-06-19 11:29:52 +02:00
|
|
|
}
|
|
|
|
}
|