php-censor/src/Plugin/Atoum.php

110 lines
2.1 KiB
PHP
Raw Permalink Normal View History

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
/**
* 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';
}
/**
2016-07-11 18:00:04 +02:00
* {@inheritdoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
2013-06-19 11:29:52 +02:00
{
parent::__construct($builder, $build, $options);
2013-06-19 11:29:52 +02:00
if (isset($options['executable'])) {
$this->executable = $this->builder->buildPath . '/' . $options['executable'];
2013-08-02 12:12:17 +02:00
} else {
$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'];
}
}
/**
* Run the Atoum plugin.
2017-11-05 15:48:36 +01:00
*
* @return bool
*/
2013-06-19 11:29:52 +02:00
public function execute()
{
$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) {
$dirPath = $this->builder->buildPath . '/' . $this->directory;
$cmd .= " -d '{$dirPath}'";
2013-06-19 11:29:52 +02:00
}
2017-03-04 16:39:56 +01:00
chdir($this->builder->buildPath);
2017-03-04 16:39:56 +01:00
$output = '';
$status = true;
2017-03-04 16:39:56 +01:00
exec($cmd, $output);
2013-10-10 02:01:06 +02:00
if (count(preg_grep("/Success \(/", $output)) == 0) {
$status = false;
$this->builder->log($output);
}
2017-03-04 16:39:56 +01:00
if (count($output) == 0) {
$status = false;
$this->builder->log('No tests have been performed.');
}
2017-03-04 16:39:56 +01:00
return $status;
2013-06-19 11:29:52 +02:00
}
}