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);
error_reporting(-1);
ini_set('display_errors', 1);
require_once(dirname(__DIR__) . '/bootstrap.php');
$application = new Application();

View file

@ -39,8 +39,6 @@ if (!defined('IS_WIN')) {
require_once(ROOT_DIR . 'vendor/autoload.php');
\PHPCensor\ErrorHandler::register();
if (defined('IS_CONSOLE') && IS_CONSOLE) {
$loggerConfig = LoggerConfig::newFromFile(APP_DIR . "loggerconfig.php");
}
@ -66,4 +64,4 @@ if (!defined('IS_CONSOLE')) {
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) {
$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()) {

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.
if ($exception) {
$context['exception'] = $exception;
$context['trace'] = $exception->getTrace();
}
$this->log("\033[0;31m" . $message . "\033[0m", LogLevel::ERROR, $context);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,6 +25,14 @@ class Env extends Plugin
{
protected $env_vars;
/**
* @return string
*/
public static function pluginName()
{
return 'env';
}
/**
* 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>
(%COMMIT_EMAIL%)> on branch <a href="%BRANCH_URI%">%BRANCH%</a>';
/**
* @return string
*/
public static function pluginName()
{
return 'flowdock_notify';
}
/**
* {@inheritdoc}
*/

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -28,6 +28,14 @@ class PhpTalLint extends Plugin
protected $suffixes;
protected $ignore;
/**
* @return string
*/
public static function pluginName()
{
return 'php_tal_lint';
}
/**
* @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 */
protected $options = array();
/**
* @return string
*/
public static function pluginName()
{
return 'php_unit';
}
/**
* Standard Constructor
* $options['config'] Path to a PHPUnit XML configuration file.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,11 +18,19 @@ class ExamplePluginFull extends Plugin {
/**
* @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 = [])
{
$this->Options = $options;
$this->options = $options;
}
public function execute()

View file

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

View file

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

View file

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

View file

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

View file

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