Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created August 8, 2013 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/6185448 to your computer and use it in GitHub Desktop.
Save dongilbert/6185448 to your computer and use it in GitHub Desktop.
Codeception plugin for PHPCI
<?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;
/**
* Codeception Plugin - Enables full acceptance, unit, and functional testing.
* @author Don Gilbert <don@dongilbert.net>
* @package PHPCI
* @subpackage Plugins
*/
class CodeCeption implements \PHPCI\Plugin
{
protected $args;
protected $phpci;
/**
* @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit
*/
protected $xmlConfigFile;
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
if (isset($options['config'])) {
$this->xmlConfigFile = $options['config'];
}
if (isset($options['args'])) {
$this->args = $options['args'];
}
}
/**
* 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 {
$cmd = PHPCI_BIN_DIR . 'codecept run -c "%s"';
$success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $configPath);
return $success;
}
}
protected function recurseArg($array, $callable)
{
$success = true;
foreach ($array as $subItem) {
$success &= call_user_func($callable, $subItem);
}
return $success;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment