extract the success/failure logging of the builder to an interface.
This commit is contained in:
parent
912776801d
commit
6aed18158b
31
PHPCI/BuildLogger.php
Normal file
31
PHPCI/BuildLogger.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
namespace PHPCI;
|
||||
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* PHPCI Build Logger
|
||||
*/
|
||||
interface BuildLogger
|
||||
{
|
||||
/**
|
||||
* Add an entry to the build log.
|
||||
* @param string|string[] $message
|
||||
* @param string $level
|
||||
* @param mixed[] $context
|
||||
*/
|
||||
public function log($message, $level = LogLevel::INFO, $context = array());
|
||||
|
||||
/**
|
||||
* Add a success-coloured message to the log.
|
||||
* @param string
|
||||
*/
|
||||
public function logSuccess($message);
|
||||
|
||||
/**
|
||||
* Add a failure-coloured message to the log.
|
||||
* @param string $message
|
||||
* @param \Exception $exception The exception that caused the error.
|
||||
*/
|
||||
public function logFailure($message, \Exception $exception = null);
|
||||
}
|
|
@ -21,7 +21,7 @@ use Psr\Log\LogLevel;
|
|||
* PHPCI Build Runner
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class Builder implements LoggerAwareInterface
|
||||
class Builder implements LoggerAwareInterface, BuildLogger
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
|
|
@ -2,25 +2,25 @@
|
|||
|
||||
namespace PHPCI\Plugin\Util;
|
||||
|
||||
use PHPCI\Builder;
|
||||
use PHPCI\BuildLogger;
|
||||
|
||||
class Executor
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
* @var BuildLogger
|
||||
*/
|
||||
protected $builder;
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
protected $pluginFactory;
|
||||
|
||||
function __construct(Factory $pluginFactory, Builder $builder)
|
||||
function __construct(Factory $pluginFactory, BuildLogger $logger)
|
||||
{
|
||||
$this->pluginFactory = $pluginFactory;
|
||||
$this->builder = $builder;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class Executor
|
|||
}
|
||||
|
||||
foreach ($config[$stage] as $plugin => $options) {
|
||||
$this->builder->log('RUNNING PLUGIN: ' . $plugin);
|
||||
$this->logger->log('RUNNING PLUGIN: ' . $plugin);
|
||||
|
||||
// Is this plugin allowed to fail?
|
||||
if ($stage == 'test' && !isset($options['allow_failures'])) {
|
||||
|
@ -47,7 +47,7 @@ class Executor
|
|||
if ($this->executePlugin($plugin, $options)) {
|
||||
|
||||
// Execution was successful:
|
||||
$this->builder->logSuccess('PLUGIN STATUS: SUCCESS!');
|
||||
$this->logger->logSuccess('PLUGIN STATUS: SUCCESS!');
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -57,7 +57,7 @@ class Executor
|
|||
$this->success = false;
|
||||
}
|
||||
|
||||
$this->builder->logFailure('PLUGIN STATUS: FAILED');
|
||||
$this->logger->logFailure('PLUGIN STATUS: FAILED');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class Executor
|
|||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
$this->builder->logFailure('Plugin does not exist: ' . $plugin);
|
||||
$this->logger->logFailure('Plugin does not exist: ' . $plugin);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class Executor
|
|||
$rtn = false;
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->builder->logFailure('EXCEPTION: ' . $ex->getMessage(), $ex);
|
||||
$this->logger->logFailure('EXCEPTION: ' . $ex->getMessage(), $ex);
|
||||
$rtn = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue