2013-10-08 11:21:54 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://www.phptesting.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
|
|
|
|
2013-10-08 11:21:54 +02:00
|
|
|
/**
|
|
|
|
* Codeception Plugin - Enables full acceptance, unit, and functional testing.
|
|
|
|
* @author Don Gilbert <don@dongilbert.net>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class Codeception implements \PHPCI\Plugin
|
|
|
|
{
|
2014-03-24 16:55:42 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $args = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Builder
|
|
|
|
*/
|
2013-10-08 11:21:54 +02:00
|
|
|
protected $phpci;
|
|
|
|
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
|
|
|
|
2013-10-08 11:21:54 +02:00
|
|
|
/**
|
|
|
|
* @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit
|
|
|
|
*/
|
|
|
|
protected $xmlConfigFile;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-10-08 11:21:54 +02:00
|
|
|
{
|
2014-03-24 16:55:42 +01:00
|
|
|
$this->phpci = $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->build = $build;
|
2013-10-08 11:21:54 +02:00
|
|
|
|
|
|
|
if (isset($options['config'])) {
|
|
|
|
$this->xmlConfigFile = $options['config'];
|
|
|
|
}
|
|
|
|
if (isset($options['args'])) {
|
2014-03-24 16:55:42 +01:00
|
|
|
$this->args = (string) $options['args'];
|
2013-10-08 11:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs Codeception tests, optionally using specified config file(s).
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$success = true;
|
|
|
|
|
|
|
|
// Run any config files first. This can be either a single value or an array.
|
|
|
|
if ($this->xmlConfigFile !== null) {
|
|
|
|
$success &= $this->runConfigFile($this->xmlConfigFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function runConfigFile($configPath)
|
|
|
|
{
|
|
|
|
if (is_array($configPath)) {
|
|
|
|
return $this->recurseArg($configPath, array($this, "runConfigFile"));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$codecept = $this->phpci->findBinary('codecept');
|
|
|
|
|
|
|
|
if (!$codecept) {
|
|
|
|
$this->phpci->logFailure('Could not find codeception.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-24 16:55:42 +01:00
|
|
|
$cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" '. $this->args;
|
2014-03-12 18:37:57 +01:00
|
|
|
if (IS_WIN) {
|
2014-03-24 16:55:42 +01:00
|
|
|
$cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" '. $this->args;
|
2014-03-12 18:37:57 +01:00
|
|
|
}
|
2014-05-01 17:53:29 +02:00
|
|
|
|
|
|
|
$configPath = $this->phpci->buildPath . $configPath;
|
|
|
|
$success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath);
|
2013-10-08 11:21:54 +02:00
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function recurseArg($array, $callable)
|
|
|
|
{
|
|
|
|
$success = true;
|
|
|
|
foreach ($array as $subItem) {
|
|
|
|
$success &= call_user_func($callable, $subItem);
|
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
2013-10-10 02:01:06 +02:00
|
|
|
}
|