php-censor/src/PHPCensor/Plugin/Atoum.php

92 lines
2.3 KiB
PHP
Raw Normal View History

2013-06-19 11:29:52 +02:00
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
2013-06-19 11:29:52 +02:00
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\Helper\Lang;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
2013-10-10 02:01:06 +02:00
/**
* Atoum plugin, runs Atoum tests within a project.
* @package PHPCensor\Plugin
*/
2016-05-09 08:20:26 +02:00
class Atoum implements Plugin
2013-06-19 11:29:52 +02:00
{
private $args;
private $config;
private $directory;
/**
* Set up the plugin, configure options, etc.
* @param Builder $phpci
* @param Build $build
* @param array $options
*/
2016-04-21 06:58:09 +02:00
public function __construct(Builder $phpci, Build $build, array $options = [])
2013-06-19 11:29:52 +02:00
{
$this->phpci = $phpci;
2013-10-10 02:01:06 +02:00
$this->build = $build;
2013-06-19 11:29:52 +02:00
if (isset($options['executable'])) {
$this->executable = $this->phpci->buildPath . DIRECTORY_SEPARATOR.$options['executable'];
2013-08-02 12:12:17 +02:00
} else {
2013-10-08 09:50:10 +02:00
$this->executable = $this->phpci->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.
* @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}";
}
if ($this->config !== null) {
$cmd .= " -c '{$this->config}'";
}
if ($this->directory !== null) {
$dirPath = $this->phpci->buildPath . DIRECTORY_SEPARATOR . $this->directory;
$cmd .= " -d '{$dirPath}'";
2013-06-19 11:29:52 +02:00
}
chdir($this->phpci->buildPath);
$output = '';
$status = true;
exec($cmd, $output);
2013-10-10 02:01:06 +02:00
if (count(preg_grep("/Success \(/", $output)) == 0) {
$status = false;
$this->phpci->log($output);
}
if (count($output) == 0) {
$status = false;
2014-12-04 16:48:52 +01:00
$this->phpci->log(Lang::get('no_tests_performed'));
}
return $status;
2013-06-19 11:29:52 +02:00
}
}