phpci/PHPCI/Plugin/Behat.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2013-10-08 11:26:11 +02:00
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
2013-10-08 11:26:11 +02:00
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
2013-10-08 11:26:11 +02:00
*/
namespace PHPCI\Plugin;
2013-10-10 02:01:06 +02:00
use PHPCI\Builder;
use PHPCI\Model\Build;
2013-10-08 11:26:11 +02:00
/**
* Behat BDD Plugin
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class Behat implements \PHPCI\Plugin
{
protected $phpci;
2014-05-02 15:48:40 +02:00
protected $build;
2013-10-10 02:01:06 +02:00
protected $features;
2013-10-08 11:26:11 +02:00
/**
* Standard Constructor
*
* $options['directory'] Output Directory. Default: %BUILDPATH%
* $options['filename'] Phar Filename. Default: build.phar
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
* $options['stub'] Stub Content. No Default Value
*
* @param Builder $phpci
* @param Build $build
* @param array $options
*/
2013-10-10 02:01:06 +02:00
public function __construct(Builder $phpci, Build $build, array $options = array())
2013-10-08 11:26:11 +02:00
{
2014-05-16 16:14:14 +02:00
$this->phpci = $phpci;
$this->build = $build;
2013-10-10 02:01:06 +02:00
$this->features = '';
if (isset($options['executable'])) {
$this->executable = $options['executable'];
} else {
2014-05-16 16:14:14 +02:00
$this->executable = $this->phpci->findBinary('behat');
}
2013-10-10 02:01:06 +02:00
if (!empty($options['features'])) {
$this->features = $options['features'];
}
2013-10-08 11:26:11 +02:00
}
/**
* Runs Behat tests.
*/
public function execute()
{
$curdir = getcwd();
chdir($this->phpci->buildPath);
$behat = $this->executable;
2013-10-08 11:26:11 +02:00
2013-10-10 02:01:06 +02:00
if (!$behat) {
$this->phpci->logFailure('Could not find behat.');
2013-10-08 11:26:11 +02:00
return false;
}
$success = $this->phpci->executeCommand($behat . ' %s', $this->features);
2013-10-08 11:26:11 +02:00
chdir($curdir);
return $success;
}
}