Fixes for build without config

This commit is contained in:
Dmitry Khomutov 2017-01-11 22:15:54 +07:00
parent a5aabdce2d
commit 86478a1264
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
56 changed files with 376 additions and 85 deletions

View file

@ -24,6 +24,9 @@ use PHPCensor\Console\Application;
define('IS_CONSOLE', true); define('IS_CONSOLE', true);
error_reporting(-1);
ini_set('display_errors', 1);
require_once(dirname(__DIR__) . '/bootstrap.php'); require_once(dirname(__DIR__) . '/bootstrap.php');
$application = new Application(); $application = new Application();

View file

@ -39,8 +39,6 @@ if (!defined('IS_WIN')) {
require_once(ROOT_DIR . 'vendor/autoload.php'); require_once(ROOT_DIR . 'vendor/autoload.php');
\PHPCensor\ErrorHandler::register();
if (defined('IS_CONSOLE') && IS_CONSOLE) { if (defined('IS_CONSOLE') && IS_CONSOLE) {
$loggerConfig = LoggerConfig::newFromFile(APP_DIR . "loggerconfig.php"); $loggerConfig = LoggerConfig::newFromFile(APP_DIR . "loggerconfig.php");
} }
@ -66,4 +64,4 @@ if (!defined('IS_CONSOLE')) {
define('IS_CONSOLE', false); define('IS_CONSOLE', false);
} }
\PHPCensor\Helper\Lang::init($config); \PHPCensor\Helper\Lang::init($config, 'ru');

View file

@ -231,7 +231,7 @@ class Builder implements LoggerAwareInterface
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->build->setStatus(Build::STATUS_FAILED); $this->build->setStatus(Build::STATUS_FAILED);
$this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex);
} }
if (Build::STATUS_FAILED === $this->build->getStatus()) { if (Build::STATUS_FAILED === $this->build->getStatus()) {

View file

@ -1,68 +0,0 @@
<?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/
*/
namespace PHPCensor;
/**
* Error Handler
*
* @package PHPCensor\Logging
*/
class ErrorHandler
{
/**
* @var array
*/
protected $levels = [
E_WARNING => 'Warning',
E_NOTICE => 'Notice',
E_USER_ERROR => 'User Error',
E_USER_WARNING => 'User Warning',
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Runtime Notice',
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated',
];
/**
* Registers an instance of the error handler to throw ErrorException.
*/
public static function register()
{
$handler = new static();
set_error_handler([$handler, 'handleError']);
}
/**
* @param integer $level
* @param string $message
* @param string $file
* @param integer $line
*
* @throws \ErrorException
*
* @internal
*/
public function handleError($level, $message, $file, $line)
{
if (error_reporting() & $level === 0) {
return;
}
$exceptionLevel = isset($this->levels[$level]) ? $this->levels[$level] : $level;
throw new \ErrorException(
sprintf('%s: %s in %s line %d', $exceptionLevel, $message, $file, $line),
0,
$level,
$file,
$line
);
}
}

View file

@ -89,6 +89,7 @@ class BuildLogger implements LoggerAwareInterface
// as the exception key in the context array. // as the exception key in the context array.
if ($exception) { if ($exception) {
$context['exception'] = $exception; $context['exception'] = $exception;
$context['trace'] = $exception->getTrace();
} }
$this->log("\033[0;31m" . $message . "\033[0m", LogLevel::ERROR, $context); $this->log("\033[0;31m" . $message . "\033[0m", LogLevel::ERROR, $context);

View file

@ -9,7 +9,6 @@
namespace PHPCensor\Logging; namespace PHPCensor\Logging;
use Monolog\ErrorHandler;
use Monolog\Logger; use Monolog\Logger;
/** /**
@ -68,7 +67,7 @@ class LoggerConfig
} }
$logger = new Logger($name, $handlers); $logger = new Logger($name, $handlers);
ErrorHandler::register($logger); Handler::register($logger);
$this->cache[$name] = $logger; $this->cache[$name] = $logger;
return $logger; return $logger;

View file

@ -110,8 +110,11 @@ class Build extends BuildBase
} }
} }
$yamlParser = new YamlParser(); // for YAML configs from files/DB
$build_config = $yamlParser->parse($build_config); if (is_string($build_config)) {
$yamlParser = new YamlParser();
$build_config = $yamlParser->parse($build_config);
}
$builder->setConfigArray($build_config); $builder->setConfigArray($build_config);
@ -159,7 +162,7 @@ class Build extends BuildBase
foreach (['setup', 'test', 'complete', 'success', 'failure'] as $stage) { foreach (['setup', 'test', 'complete', 'success', 'failure'] as $stage) {
if ($className::canExecute($stage, $builder, $this)) { if ($className::canExecute($stage, $builder, $this)) {
$config[$stage][$className] = [ $config[$stage][$className::pluginName()] = [
'zero_config' => true 'zero_config' => true
]; ];
} }

View file

@ -67,4 +67,12 @@ abstract class Plugin
* @return boolean * @return boolean
*/ */
abstract public function execute(); abstract public function execute();
/**
* @return string
*/
public static function pluginName()
{
return '';
}
} }

View file

@ -26,6 +26,14 @@ class Atoum extends Plugin
protected $config; protected $config;
protected $directory; protected $directory;
/**
* @return string
*/
public static function pluginName()
{
return 'atoum';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -27,6 +27,14 @@ class Behat extends Plugin
protected $features; protected $features;
protected $executable; protected $executable;
/**
* @return string
*/
public static function pluginName()
{
return 'behat';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -32,6 +32,14 @@ class Campfire extends Plugin
protected $roomId; protected $roomId;
protected $message; protected $message;
/**
* @return string
*/
public static function pluginName()
{
return 'campfire';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -25,6 +25,14 @@ class CleanBuild extends Plugin
{ {
protected $remove; protected $remove;
/**
* @return string
*/
public static function pluginName()
{
return 'clean_build';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -41,6 +41,14 @@ class Codeception extends Plugin implements ZeroConfigPlugin
*/ */
protected $path; protected $path;
/**
* @return string
*/
public static function pluginName()
{
return 'codeception';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -31,6 +31,14 @@ class Composer extends Plugin implements ZeroConfigPlugin
protected $ignorePlatformReqs; protected $ignorePlatformReqs;
protected $preferSource; protected $preferSource;
/**
* @return string
*/
public static function pluginName()
{
return 'composer';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -27,6 +27,14 @@ class CopyBuild extends Plugin
protected $ignore; protected $ignore;
protected $wipe; protected $wipe;
/**
* @return string
*/
public static function pluginName()
{
return 'copy_build';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -27,6 +27,14 @@ class Deployer extends Plugin
protected $reason; protected $reason;
protected $updateOnly; protected $updateOnly;
/**
* @return string
*/
public static function pluginName()
{
return 'deployer';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -29,6 +29,14 @@ use PHPCensor\Plugin;
*/ */
class Email extends Plugin class Email extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'email';
}
/** /**
* Send a notification mail. * Send a notification mail.
* *

View file

@ -25,6 +25,14 @@ class Env extends Plugin
{ {
protected $env_vars; protected $env_vars;
/**
* @return string
*/
public static function pluginName()
{
return 'env';
}
/** /**
* Adds the specified environment variables to the builder environment * Adds the specified environment variables to the builder environment
*/ */

View file

@ -30,6 +30,14 @@ class FlowdockNotify extends Plugin
const MESSAGE_DEFAULT = 'Build %BUILD% has finished for commit <a href="%COMMIT_URI%">%SHORT_COMMIT%</a> const MESSAGE_DEFAULT = 'Build %BUILD% has finished for commit <a href="%COMMIT_URI%">%SHORT_COMMIT%</a>
(%COMMIT_EMAIL%)> on branch <a href="%BRANCH_URI%">%BRANCH%</a>'; (%COMMIT_EMAIL%)> on branch <a href="%BRANCH_URI%">%BRANCH%</a>';
/**
* @return string
*/
public static function pluginName()
{
return 'flowdock_notify';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -25,6 +25,14 @@ class Git extends Plugin
{ {
protected $actions = []; protected $actions = [];
/**
* @return string
*/
public static function pluginName()
{
return 'git';
}
/** /**
* Run the Git plugin. * Run the Git plugin.
* @return bool * @return bool

View file

@ -28,6 +28,14 @@ class Grunt extends Plugin
protected $grunt; protected $grunt;
protected $gruntfile; protected $gruntfile;
/**
* @return string
*/
public static function pluginName()
{
return 'grunt';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -28,6 +28,14 @@ class Gulp extends Plugin
protected $gulp; protected $gulp;
protected $gulpfile; protected $gulpfile;
/**
* @return string
*/
public static function pluginName()
{
return 'gulp';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -32,6 +32,14 @@ class HipchatNotify extends Plugin
protected $message; protected $message;
protected $room; protected $room;
/**
* @return string
*/
public static function pluginName()
{
return 'hipchat_notify';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -29,6 +29,14 @@ class Irc extends Plugin
protected $room; protected $room;
protected $nick; protected $nick;
/**
* @return string
*/
public static function pluginName()
{
return 'irc';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -27,6 +27,14 @@ class Lint extends Plugin
protected $recursive = true; protected $recursive = true;
protected $ignore; protected $ignore;
/**
* @return string
*/
public static function pluginName()
{
return 'lint';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -41,6 +41,14 @@ class Mysql extends Plugin
*/ */
protected $pass; protected $pass;
/**
* @return string
*/
public static function pluginName()
{
return 'mysql';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -26,6 +26,14 @@ class PackageBuild extends Plugin
protected $filename; protected $filename;
protected $format; protected $format;
/**
* @return string
*/
public static function pluginName()
{
return 'package_build';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -50,6 +50,14 @@ class Pdepend extends Plugin
*/ */
protected $location; protected $location;
/**
* @return string
*/
public static function pluginName()
{
return 'pdepend';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -38,6 +38,14 @@ class Pgsql extends Plugin
*/ */
protected $pass; protected $pass;
/**
* @return string
*/
public static function pluginName()
{
return 'pgsql';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -38,6 +38,14 @@ class Phar extends Plugin
*/ */
protected $stub; protected $stub;
/**
* @return string
*/
public static function pluginName()
{
return 'phar';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -23,13 +23,20 @@ use PHPCensor\Plugin;
*/ */
class Phing extends Plugin class Phing extends Plugin
{ {
protected $directory; protected $directory;
protected $buildFile = 'build.xml'; protected $buildFile = 'build.xml';
protected $targets = ['build']; protected $targets = ['build'];
protected $properties = []; protected $properties = [];
protected $propertyFile; protected $propertyFile;
/**
* @return string
*/
public static function pluginName()
{
return 'phing';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -71,6 +71,14 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPlugin
*/ */
protected $ignore; protected $ignore;
/**
* @return string
*/
public static function pluginName()
{
return 'php_code_sniffer';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -39,6 +39,14 @@ class PhpCpd extends Plugin implements ZeroConfigPlugin
*/ */
protected $ignore; protected $ignore;
/**
* @return string
*/
public static function pluginName()
{
return 'php_cpd';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -28,6 +28,14 @@ class PhpCsFixer extends Plugin
protected $diff = ''; protected $diff = '';
protected $levels = ['psr0', 'psr1', 'psr2', 'symfony']; protected $levels = ['psr0', 'psr1', 'psr2', 'symfony'];
/**
* @return string
*/
public static function pluginName()
{
return 'php_cs_fixer';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -39,6 +39,14 @@ class PhpDocblockChecker extends Plugin implements ZeroConfigPlugin
protected $skipMethods = false; protected $skipMethods = false;
protected $allowed_warnings; protected $allowed_warnings;
/**
* @return string
*/
public static function pluginName()
{
return 'php_docblock_checker';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -29,6 +29,14 @@ class PhpLoc extends Plugin implements ZeroConfigPlugin
*/ */
protected $directory; protected $directory;
/**
* @return string
*/
public static function pluginName()
{
return 'php_loc';
}
/** /**
* Check if this plugin can be executed. * Check if this plugin can be executed.
* @param $stage * @param $stage

View file

@ -49,6 +49,14 @@ class PhpMessDetector extends Plugin implements ZeroConfigPlugin
protected $rules; protected $rules;
protected $allowed_warnings; protected $allowed_warnings;
/**
* @return string
*/
public static function pluginName()
{
return 'php_mess_detector';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -38,6 +38,14 @@ class PhpParallelLint extends Plugin implements ZeroConfigPlugin
*/ */
protected $extensions; protected $extensions;
/**
* @return string
*/
public static function pluginName()
{
return 'php_parallel_lint';
}
/** /**
* $options['directory'] Output Directory. Default: %BUILDPATH% * $options['directory'] Output Directory. Default: %BUILDPATH%
* $options['filename'] Phar Filename. Default: build.phar * $options['filename'] Phar Filename. Default: build.phar

View file

@ -23,6 +23,14 @@ use PHPCensor\Plugin;
*/ */
class PhpSpec extends Plugin class PhpSpec extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'php_spec';
}
/** /**
* Runs PHP Spec tests. * Runs PHP Spec tests.
*/ */

View file

@ -28,6 +28,14 @@ class PhpTalLint extends Plugin
protected $suffixes; protected $suffixes;
protected $ignore; protected $ignore;
/**
* @return string
*/
public static function pluginName()
{
return 'php_tal_lint';
}
/** /**
* @var string The path to a file contain custom phptal_tales_ functions * @var string The path to a file contain custom phptal_tales_ functions
*/ */

View file

@ -32,6 +32,14 @@ class PhpUnit extends Plugin implements ZeroConfigPlugin
/** @var string[] Raw options from the PHPCI config file */ /** @var string[] Raw options from the PHPCI config file */
protected $options = array(); protected $options = array();
/**
* @return string
*/
public static function pluginName()
{
return 'php_unit';
}
/** /**
* Standard Constructor * Standard Constructor
* $options['config'] Path to a PHPUnit XML configuration file. * $options['config'] Path to a PHPUnit XML configuration file.

View file

@ -29,6 +29,14 @@ class Shell extends Plugin
*/ */
protected $commands = []; protected $commands = [];
/**
* @return string
*/
public static function pluginName()
{
return 'shell';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -31,6 +31,14 @@ class SlackNotify extends Plugin
private $icon; private $icon;
private $show_status; private $show_status;
/**
* @return string
*/
public static function pluginName()
{
return 'slack_notify';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -33,6 +33,14 @@ class Sqlite extends Plugin
*/ */
protected $path; protected $path;
/**
* @return string
*/
public static function pluginName()
{
return 'sqlite';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -55,6 +55,14 @@ class TechnicalDebt extends Plugin implements ZeroConfigPlugin
*/ */
protected $searches; protected $searches;
/**
* @return string
*/
public static function pluginName()
{
return 'technical_debt';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -24,6 +24,14 @@ class Wipe extends Plugin
{ {
protected $directory; protected $directory;
/**
* @return string
*/
public static function pluginName()
{
return 'wipe';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -59,6 +59,14 @@ class XMPP extends Plugin
*/ */
protected $date_format; protected $date_format;
/**
* @return string
*/
public static function pluginName()
{
return 'xmpp';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -90,7 +90,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase
$view->tmp = $tmp; $view->tmp = $tmp;
$this->assertTrue($view->render() == 'Hello '); $this->assertTrue($view->render() == 'Hello ');
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf('\ErrorException', $e); self::assertInstanceOf('\PHPUnit_Framework_Error_Notice', $e);
} }
$view = new Template('Hello {@who.toUpperCase}'); $view = new Template('Hello {@who.toUpperCase}');

View file

@ -129,8 +129,8 @@ class FactoryTest extends \PHPUnit_Framework_TestCase {
$expectedArgs $expectedArgs
); );
$this->assertInternalType('array', $plugin->Options); $this->assertInternalType('array', $plugin->options);
$this->assertArrayHasKey('thing', $plugin->Options); $this->assertArrayHasKey('thing', $plugin->options);
} }
public function testAddConfigFromFile_ReturnsTrueForValidFile() public function testAddConfigFromFile_ReturnsTrueForValidFile()

View file

@ -18,11 +18,19 @@ class ExamplePluginFull extends Plugin {
/** /**
* @var array * @var array
*/ */
public $Options; public $options;
/**
* @return string
*/
public static function pluginName()
{
return 'example_plugin_full';
}
public function __construct(Builder $builder, Build $build, array $options = []) public function __construct(Builder $builder, Build $build, array $options = [])
{ {
$this->Options = $options; $this->options = $options;
} }
public function execute() public function execute()

View file

@ -14,6 +14,14 @@ use PHPCensor\Plugin;
class ExamplePluginWithNoConstructorArgs extends Plugin class ExamplePluginWithNoConstructorArgs extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'example_plugin_with_no_constructor_args';
}
public function execute() public function execute()
{ {
} }

View file

@ -14,6 +14,14 @@ use PHPCensor\Plugin;
class ExamplePluginWithSingleOptionalArg extends Plugin class ExamplePluginWithSingleOptionalArg extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'example_plugin_with_single_optional_arg';
}
function __construct($optional = null) function __construct($optional = null)
{ {

View file

@ -14,6 +14,13 @@ use PHPCensor\Plugin;
class ExamplePluginWithSingleRequiredArg extends Plugin class ExamplePluginWithSingleRequiredArg extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'example_plugin_with_single_required_arg';
}
public $RequiredArgument; public $RequiredArgument;

View file

@ -14,6 +14,13 @@ use PHPCensor\Plugin;
class ExamplePluginWithSingleTypedRequiredArg extends Plugin class ExamplePluginWithSingleTypedRequiredArg extends Plugin
{ {
/**
* @return string
*/
public static function pluginName()
{
return 'example_plugin_with_single_typed_required_arg';
}
public $RequiredArgument; public $RequiredArgument;

View file

@ -39,8 +39,6 @@ if (!defined('IS_WIN')) {
require_once(ROOT_DIR . 'vendor/autoload.php'); require_once(ROOT_DIR . 'vendor/autoload.php');
\PHPCensor\ErrorHandler::register();
if (defined('IS_CONSOLE') && IS_CONSOLE) { if (defined('IS_CONSOLE') && IS_CONSOLE) {
$loggerConfig = LoggerConfig::newFromFile(APP_DIR . "loggerconfig.php"); $loggerConfig = LoggerConfig::newFromFile(APP_DIR . "loggerconfig.php");
} }