From 1fe8d68f0331c66e6b5fff5e67dbde2d40f3f08c Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 17 Mar 2018 17:52:34 +0700 Subject: [PATCH 1/9] Refactored 'build/view' action. --- public/assets/js/app.js | 14 ++ src/Controller/BuildController.php | 74 ++++++++- src/View/Build/errors.phtml | 30 ++-- src/View/Build/viewLog.phtml | 205 +++++++++++++++++++++++++ src/View/WidgetBuildErrors/index.phtml | 4 + 5 files changed, 314 insertions(+), 13 deletions(-) create mode 100644 src/View/Build/viewLog.phtml diff --git a/public/assets/js/app.js b/public/assets/js/app.js index 644d7974..c37723cd 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -498,3 +498,17 @@ var Lang = { return string; } }; + +jquery(document).ready(function() { + jquery('#delete-build').on('click', function (e) { + e.preventDefault(); + + var buildId = this.data('buildId'); + var projectId = this.data('projectId'); + + confirmDelete(APP_URL + 'build/delete/' + buildId) + .onCloseConfirmed = function () { + window.location = APP_URL + 'project/view/' + projectId; + }; + }); +}); diff --git a/src/Controller/BuildController.php b/src/Controller/BuildController.php index 3db8143b..7430449a 100644 --- a/src/Controller/BuildController.php +++ b/src/Controller/BuildController.php @@ -10,6 +10,7 @@ use PHPCensor\Helper\AnsiConverter; use PHPCensor\Helper\Lang; use PHPCensor\Http\Response\RedirectResponse; use PHPCensor\Model\Build; +use PHPCensor\Model\Project; use PHPCensor\Model\User; use PHPCensor\Service\BuildService; use PHPCensor\WebController; @@ -47,8 +48,6 @@ class BuildController extends WebController } /** - * View a specific build. - * * @param integer $buildId * * @throws NotFoundException @@ -143,6 +142,77 @@ class BuildController extends WebController $this->layout->actions = $actions; } + /** + * @param integer $buildId + * + * @throws NotFoundException + */ + public function viewLog($buildId) + { + $build = BuildFactory::getBuildById($buildId); + + if (!$build) { + throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); + } + + /** @var Project $project */ + $project = Factory::getStore('Project')->getByPrimaryKey($build->getProjectId()); + + /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ + $errorStore = Factory::getStore('BuildError'); + + $this->view->build = $build; + $this->view->totalErrors = $errorStore->getErrorTotalForBuild($build->getId()); + + $this->layout->title = Lang::get('build_n', $buildId); + $this->layout->subtitle = $build->getProjectTitle(); + + switch ($build->getStatus()) { + case 0: + $this->layout->skin = 'blue'; + break; + + case 1: + $this->layout->skin = 'yellow'; + break; + + case 2: + $this->layout->skin = 'green'; + break; + + case 3: + $this->layout->skin = 'red'; + break; + } + + $rebuildLabel = Lang::get('rebuild_now'); + $rebuildLink = APP_URL . 'build/rebuild/' . $build->getId(); + + $deleteLabel = Lang::get('delete_build'); + $deleteLink = APP_URL . 'build/delete/' . $build->getId(); + + $actions = ''; + if (!$project->getArchived()) { + $actions .= sprintf( + '%s', + $rebuildLink, + $rebuildLabel + ); + } + + if ($this->currentUserIsAdmin()) { + $actions .= sprintf( + '%s', + $build->getId(), + $build->getProjectId(), + $deleteLink, + $deleteLabel + ); + } + + $this->layout->actions = $actions; + } + /** * Returns an array of the JS plugins to include. * @return array diff --git a/src/View/Build/errors.phtml b/src/View/Build/errors.phtml index c7b87be6..979f502d 100644 --- a/src/View/Build/errors.phtml +++ b/src/View/Build/errors.phtml @@ -21,7 +21,9 @@ foreach ($errors as $error): getIsNew()): ?> - + + + @@ -29,19 +31,25 @@ foreach ($errors as $error): getSeverityString()); ?> - getPlugin()); ?> - getFile(); ?> + + getPlugin()); ?> + - getLineStart() == $error->getLineEnd() || !$error->getLineEnd()) { - echo $error->getLineStart(); - } else { - echo ($error->getLineStart() . ' - ' . $error->getLineEnd()); - } - ?> + getFile(); ?> - getMessage())); ?> + + + getLineStart() == $error->getLineEnd() || !$error->getLineEnd()): ?> + getLineStart(); ?> + + getLineStart() . ' - ' . $error->getLineEnd()); ?> + + + + + getMessage())); ?> + diff --git a/src/View/Build/viewLog.phtml b/src/View/Build/viewLog.phtml new file mode 100644 index 00000000..a09bc27d --- /dev/null +++ b/src/View/Build/viewLog.phtml @@ -0,0 +1,205 @@ + + +
+
+
+
+

+ +

+
+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + + getProject()->getTitle(); ?> + +
+ getSource()): ?> + + + getRemoteBranch(); ?> : + + + + + getBranch(); ?> + + getTag()): ?> / + + + + +
+ getEnvironment(); + echo !empty($environment) ? (' ' . $environment) : '—' ; + ?> +
+ + getBranch(); ?> + + + getExtra('branches'); + if (!empty($branches)) { + foreach($branches as $branch) { + ?> +
+
+
+
+ +
+
+
+

+ +

+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ getSourceHumanize()); ?> +
+ + getCommitId(), 0, 7); ?> + +
+ getCommitterEmail(); ?> +
+ getCommitMessage()); ?> +
+
+
+
+ +
+
+
+

+ +

+
+ +
+ + + + + + + + + + + + + + + + + + + + +
+ getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?> +
+ getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?> +
+ getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?> +
+ getDuration(); ?> +
+
+
+
+ +
+ + diff --git a/src/View/WidgetBuildErrors/index.phtml b/src/View/WidgetBuildErrors/index.phtml index 363ae597..2d42181d 100644 --- a/src/View/WidgetBuildErrors/index.phtml +++ b/src/View/WidgetBuildErrors/index.phtml @@ -2,6 +2,10 @@ use PHPCensor\Helper\Lang; +/** + * @var string $projects + */ + ?>
From 95577f178a3d156cf0933c829123dd28ace8ff3a Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 7 May 2018 20:47:04 +0700 Subject: [PATCH 2/9] ci.php-censor.info config fixes. --- .php-censor.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.php-censor.yml b/.php-censor.yml index 03ea5b68..9d0c0e80 100644 --- a/.php-censor.yml +++ b/.php-censor.yml @@ -1,5 +1,4 @@ build_settings: - clone_depth: 1 ignore: - vendor - tests @@ -14,11 +13,6 @@ test: - phpunit.xml coverage: true - php_mess_detector: - allow_failures: true - rules: - - phpmd.xml - php_code_sniffer: standard: PSR2 encoding: UTF-8 @@ -33,9 +27,6 @@ test: php_parallel_lint: allow_failures: true - php_docblock_checker: - allow_failures: true - security_checker: allow_failures: false From c2b94a5bf779d348a22dc7e0c51cd5aff21b6645 Mon Sep 17 00:00:00 2001 From: Phoebus Date: Tue, 15 May 2018 20:43:15 +0100 Subject: [PATCH 3/9] Installing HipChat via composer I was getting the following error: Class 'HipChat\HipChat' not found After checking composer.json I saw the `suggest` packages. Good to have in the documentation. --- docs/en/plugins/hipchat_notify.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/en/plugins/hipchat_notify.md b/docs/en/plugins/hipchat_notify.md index d783af65..392a5a13 100644 --- a/docs/en/plugins/hipchat_notify.md +++ b/docs/en/plugins/hipchat_notify.md @@ -4,6 +4,13 @@ Plugin Hipchat Notify This plugin joins a [HipChat](https://www.hipchat.com/) room and sends a user-defined message, for example a "Build Succeeded" message. +Install via Composer +-------------------- +``` +cd /var/www/php-censor +composer require "hipchat/hipchat-php" +``` + Configuration ------------- From a270c740c30d960e8ade822321d53c36e8b012ca Mon Sep 17 00:00:00 2001 From: Phoebus Date: Wed, 16 May 2018 17:17:06 +0100 Subject: [PATCH 4/9] php_code_sniffer not including phpcs.xml standard I thought I had the standard path wrong but after updating php_codesniffer from composer it started reading phpcs.xml. Ref: https://github.com/squizlabs/PHP_CodeSniffer/issues/1660 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5909cce5..85dfee1b 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ "codeception/codeception": "~2.3.0", "phpmd/phpmd": "~2.6.0", "sebastian/phpcpd": "~2.0.0", - "squizlabs/php_codesniffer": "~2.8.0", + "squizlabs/php_codesniffer": "~3.2.0", "block8/php-docblock-checker": "~1.3.0", "phploc/phploc": "~4.0.0", "jakub-onderka/php-parallel-lint": "~0.9.0", From b13049187e8dd03e81354c89a3e52df700fbafc9 Mon Sep 17 00:00:00 2001 From: Phoebus Apostolidis Date: Mon, 21 May 2018 10:18:27 +0100 Subject: [PATCH 5/9] Update php_code_sniffer to ~3.2.0 --- composer.lock | 51 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/composer.lock b/composer.lock index 550dfd88..ef6f9e1c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "6c8facd9ea26fd63006a35d445fac984", + "content-hash": "8ed0d649c464752b717de050e04cd313", "packages": [ { "name": "behat/gherkin", @@ -2959,64 +2959,37 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.8.1", + "version": "3.2.3", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d" + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -3033,7 +3006,7 @@ "phpcs", "standards" ], - "time": "2017-03-01T22:17:45+00:00" + "time": "2018-02-20T21:35:23+00:00" }, { "name": "swiftmailer/swiftmailer", From 456e2ace9bf6a61485263d2430a791801f80107c Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 27 May 2018 12:56:01 +0700 Subject: [PATCH 6/9] Added information about additional dependencies for some plugins (Hipchat, Slack and Flowdock). --- docs/en/README.md | 2 +- docs/en/plugins/flowdock_notify.md | 14 ++++++++++++++ docs/en/plugins/hipchat_notify.md | 10 ++++++---- docs/en/plugins/slack_notify.md | 11 ++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 docs/en/plugins/flowdock_notify.md diff --git a/docs/en/README.md b/docs/en/README.md index 963bb57f..02b8c982 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -78,7 +78,7 @@ Plugins * [Campfire](plugins/campfire.md) - `campfire` * [Email](plugins/email.md) - `email` -* FlowDock - `flowdock_notify` +* [FlowDock](plugins/flowdock_notify.md) - `flowdock_notify` * [HipChat](plugins/hipchat_notify.md) - `hipchat_notify` * [IRC](plugins/irc.md) - `irc` * [Slack](plugins/slack_notify.md) - `slack_notify` diff --git a/docs/en/plugins/flowdock_notify.md b/docs/en/plugins/flowdock_notify.md new file mode 100644 index 00000000..aa18edfa --- /dev/null +++ b/docs/en/plugins/flowdock_notify.md @@ -0,0 +1,14 @@ +Plugin FlowdockNotify +===================== + +This plugin joins a [Flowdock](https://www.flowdock.com/) room and sends a user-defined message, for example a +"Build Succeeded" message. + +Installation +------------ + +The plugin depends on `mremi/flowdock` library. To use FlowdockNotify plugin you should install dependency: + +``` +composer require "mremi/flowdock" +``` diff --git a/docs/en/plugins/hipchat_notify.md b/docs/en/plugins/hipchat_notify.md index 392a5a13..d83ece35 100644 --- a/docs/en/plugins/hipchat_notify.md +++ b/docs/en/plugins/hipchat_notify.md @@ -1,13 +1,15 @@ -Plugin Hipchat Notify +Plugin HipchatNotify ===================== This plugin joins a [HipChat](https://www.hipchat.com/) room and sends a user-defined message, for example a "Build Succeeded" message. -Install via Composer --------------------- +Installation +------------ + +The plugin depends on `hipchat/hipchat-php` library. To use HipchatNotify plugin you should install dependency: + ``` -cd /var/www/php-censor composer require "hipchat/hipchat-php" ``` diff --git a/docs/en/plugins/slack_notify.md b/docs/en/plugins/slack_notify.md index 07222902..259c5c79 100644 --- a/docs/en/plugins/slack_notify.md +++ b/docs/en/plugins/slack_notify.md @@ -1,9 +1,18 @@ -Plugin Slack Notify +Plugin SlackNotify =================== This plugin joins a [Slack](https://www.slack.com/) room and sends a user-defined message, for example a "Build Succeeded" message. +Installation +------------ + +The plugin depends on `maknz/slack` library. To use SlackNotify plugin you should install dependency: + +``` +composer require "maknz/slack" +``` + Configuration ------------- From 7bc9d1ff12d73d6914e8479a9a4e450cbb296eb2 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 27 May 2018 13:33:27 +0700 Subject: [PATCH 7/9] Improved XML loading for Codeception. Issue #182. --- src/Helper/Xml.php | 85 +++++++++++++ src/Plugin/Codeception.php | 3 +- src/Plugin/Util/PhpUnitResultJunit.php | 51 ++------ .../Util/TestResultParsers/Codeception.php | 112 +++++++++++------- 4 files changed, 163 insertions(+), 88 deletions(-) create mode 100644 src/Helper/Xml.php diff --git a/src/Helper/Xml.php b/src/Helper/Xml.php new file mode 100644 index 00000000..e3b91876 --- /dev/null +++ b/src/Helper/Xml.php @@ -0,0 +1,85 @@ +data = preg_replace(self::PATTERN, '', $bucket->data); + $consumed += $bucket->datalen; + + stream_bucket_append($out, $bucket); + } + + return PSFS_PASS_ON; + } +} + +class Xml +{ + /** + * @param $filePath + * + * @return null|\SimpleXMLElement + */ + public static function loadFromFile($filePath) + { + stream_filter_register('xml_utf8_clean', 'PHPCensor\Helper\XmlUtf8CleanFilter'); + + try { + $xml = simplexml_load_file('php://filter/read=xml_utf8_clean/resource=' . $filePath); + } catch (\Exception $ex) { + $xml = null; + } catch (\Throwable $ex) { // since php7 + $xml = null; + } + + if (!$xml) { + // from https://stackoverflow.com/questions/7766455/how-to-handle-invalid-unicode-with-simplexml/8092672#8092672 + $oldUse = libxml_use_internal_errors(true); + + libxml_clear_errors(); + + $dom = new \DOMDocument("1.0", "UTF-8"); + + $dom->strictErrorChecking = false; + $dom->validateOnParse = false; + $dom->recover = true; + + $dom->loadXML(strtr( + file_get_contents($filePath), + ['"' => "'"] // " in attribute names may mislead the parser + )); + + /** @var \LibXMLError $xmlError */ + $xmlError = libxml_get_last_error(); + if ($xmlError) { + $warning = sprintf('L%s C%s: %s', $xmlError->line, $xmlError->column, $xmlError->message); + print 'WARNING: ignored errors while reading phpunit result, '.$warning."\n"; + } + + if (!$dom->hasChildNodes()) { + new \SimpleXMLElement(''); + } + + $xml = simplexml_import_dom($dom); + + libxml_clear_errors(); + libxml_use_internal_errors($oldUse); + } + + return $xml; + } +} diff --git a/src/Plugin/Codeception.php b/src/Plugin/Codeception.php index d5e8e1d4..585aea4e 100644 --- a/src/Plugin/Codeception.php +++ b/src/Plugin/Codeception.php @@ -145,8 +145,7 @@ class Codeception extends Plugin implements ZeroConfigPluginInterface } } - $xml = file_get_contents($outputPath . 'report.xml', false); - $parser = new Parser($this->builder, $xml); + $parser = new Parser($this->builder, ($outputPath . 'report.xml')); $output = $parser->parse(); $meta = [ diff --git a/src/Plugin/Util/PhpUnitResultJunit.php b/src/Plugin/Util/PhpUnitResultJunit.php index 3e149105..14ec1c7f 100644 --- a/src/Plugin/Util/PhpUnitResultJunit.php +++ b/src/Plugin/Util/PhpUnitResultJunit.php @@ -2,6 +2,8 @@ namespace PHPCensor\Plugin\Util; +use PHPCensor\Helper\Xml; + /** * Class PhpUnitResultJunit parses the results for the PhpUnitV2 plugin * @@ -24,11 +26,11 @@ class PhpUnitResultJunit extends PhpUnitResult $suites = $this->loadResultFile(); - foreach ($suites->xpath('//testcase') as $testCase) { - $this->parseTestcase($testCase); + if ($suites) { + foreach ($suites->xpath('//testcase') as $testCase) { + $this->parseTestcase($testCase); + } } - $suites['failures']; - $suites['errors']; return $this; } @@ -139,44 +141,7 @@ class PhpUnitResultJunit extends PhpUnitResult return new \SimpleXMLElement(''); // new empty element } - try { - $suites = simplexml_load_file($this->outputFile); - } catch (\Exception $ex) { - $suites = null; - } catch (\Throwable $ex) { // since php7 - $suites = null; - } - if (!$suites) { - // from https://stackoverflow.com/questions/7766455/how-to-handle-invalid-unicode-with-simplexml/8092672#8092672 - $oldUse = libxml_use_internal_errors(true); - libxml_clear_errors(); - $dom = new \DOMDocument("1.0", "UTF-8"); - $dom->strictErrorChecking = false; - $dom->validateOnParse = false; - $dom->recover = true; - $dom->loadXML(strtr( - file_get_contents($this->outputFile), - array('"' => "'") // " in attribute names may mislead the parser - )); - - /** - * @var \LibXMLError - */ - $xmlError = libxml_get_last_error(); - if ($xmlError) { - $warning = sprintf('L%s C%s: %s', $xmlError->line, $xmlError->column, $xmlError->message); - print 'WARNING: ignored errors while reading phpunit result, '.$warning."\n"; - } - if (!$dom->hasChildNodes()) { - $this->internalProblem('xml file with no content'); - } - $suites = simplexml_import_dom($dom); - - libxml_clear_errors(); - libxml_use_internal_errors($oldUse); - } - - return $suites; + return Xml::loadFromFile($this->outputFile); } /** @@ -185,7 +150,5 @@ class PhpUnitResultJunit extends PhpUnitResult private function internalProblem($description) { throw new \RuntimeException($description); - - // alternative to error throwing: append to $this->errors } } diff --git a/src/Plugin/Util/TestResultParsers/Codeception.php b/src/Plugin/Util/TestResultParsers/Codeception.php index dfd97cae..90fcbb2e 100644 --- a/src/Plugin/Util/TestResultParsers/Codeception.php +++ b/src/Plugin/Util/TestResultParsers/Codeception.php @@ -3,6 +3,7 @@ namespace PHPCensor\Plugin\Util\TestResultParsers; use PHPCensor\Builder; +use PHPCensor\Helper\Xml; /** * Class Codeception @@ -11,23 +12,49 @@ use PHPCensor\Builder; */ class Codeception implements ParserInterface { + /** + * @var Builder + */ protected $builder; - protected $resultsXml; + + /** + * @var string + */ + protected $xmlPath; + + /** + * @var array + */ protected $results; - protected $totalTests; - protected $totalTimeTaken; - protected $totalFailures; - protected $totalErrors; + + /** + * @var int + */ + protected $totalTests = 0; + + /** + * @var int + */ + protected $totalTimeTaken = 0; + + /** + * @var int + */ + protected $totalFailures = 0; + + /** + * @var int + */ + protected $totalErrors = 0; /** * @param Builder $builder - * @param $resultsXml + * @param string $xmlPath */ - public function __construct(Builder $builder, $resultsXml) + public function __construct(Builder $builder, $xmlPath) { - $this->builder = $builder; - $this->resultsXml = $resultsXml; - $this->totalTests = 0; + $this->builder = $builder; + $this->xmlPath = $xmlPath; } /** @@ -36,42 +63,43 @@ class Codeception implements ParserInterface public function parse() { $rtn = []; - $this->results = new \SimpleXMLElement($this->resultsXml); + $this->results = Xml::loadFromFile($this->xmlPath); - // calculate total results - foreach ($this->results->testsuite as $testSuite) { - $this->totalTests += (int)$testSuite['tests']; - $this->totalTimeTaken += (float)$testSuite['time']; - $this->totalFailures += (int)$testSuite['failures']; - $this->totalErrors += (int)$testSuite['errors']; + if ($this->results) { + foreach ($this->results->testsuite as $testSuite) { + $this->totalTests += (int)$testSuite['tests']; + $this->totalTimeTaken += (float)$testSuite['time']; + $this->totalFailures += (int)$testSuite['failures']; + $this->totalErrors += (int)$testSuite['errors']; - foreach ($testSuite->testcase as $testCase) { - $testResult = [ - 'suite' => (string)$testSuite['name'], - 'file' => str_replace($this->builder->buildPath, '/', (string) $testCase['file']), - 'name' => (string)$testCase['name'], - 'feature' => (string)$testCase['feature'], - 'assertions' => (int)$testCase['assertions'], - 'time' => (float)$testCase['time'] - ]; + foreach ($testSuite->testcase as $testCase) { + $testResult = [ + 'suite' => (string)$testSuite['name'], + 'file' => str_replace($this->builder->buildPath, '/', (string) $testCase['file']), + 'name' => (string)$testCase['name'], + 'feature' => (string)$testCase['feature'], + 'assertions' => (int)$testCase['assertions'], + 'time' => (float)$testCase['time'] + ]; - if (isset($testCase['class'])) { - $testResult['class'] = (string) $testCase['class']; + if (isset($testCase['class'])) { + $testResult['class'] = (string) $testCase['class']; + } + + // PHPUnit testcases does not have feature field. Use class::method instead + if (!$testResult['feature']) { + $testResult['feature'] = sprintf('%s::%s', $testResult['class'], $testResult['name']); + } + + if (isset($testCase->failure) || isset($testCase->error)) { + $testResult['pass'] = false; + $testResult['message'] = isset($testCase->failure) ? (string)$testCase->failure : (string)$testCase->error; + } else { + $testResult['pass'] = true; + } + + $rtn[] = $testResult; } - - // PHPUnit testcases does not have feature field. Use class::method instead - if (!$testResult['feature']) { - $testResult['feature'] = sprintf('%s::%s', $testResult['class'], $testResult['name']); - } - - if (isset($testCase->failure) || isset($testCase->error)) { - $testResult['pass'] = false; - $testResult['message'] = isset($testCase->failure) ? (string)$testCase->failure : (string)$testCase->error; - } else { - $testResult['pass'] = true; - } - - $rtn[] = $testResult; } } From b54af48bd75b66ccb2ce1361b54af98a847b5cad Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 4 Jun 2018 18:52:52 +0700 Subject: [PATCH 8/9] Fixed content type check for Gogs webhook. Issue #185. --- src/Controller/WebhookController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index e810479c..2e74c1fa 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -592,11 +592,11 @@ class WebhookController extends Controller } /** - * Called by Gogs Webhooks: - * * @param string $projectId * * @return array + * + * @throws Exception */ public function gogs($projectId) { @@ -606,14 +606,12 @@ class WebhookController extends Controller ]); switch ($_SERVER['CONTENT_TYPE']) { - case 'application/json': - $payload = json_decode(file_get_contents('php://input'), true); - break; case 'application/x-www-form-urlencoded': $payload = json_decode($this->getParam('payload'), true); break; + case 'application/json': default: - return ['status' => 'failed', 'error' => 'Content type not supported.', 'responseCode' => 401]; + $payload = json_decode(file_get_contents('php://input'), true); } // Handle Push web hooks: From 11ef5ef302d67230f3df25826952ef69767300db Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 4 Jun 2018 20:54:33 +0700 Subject: [PATCH 9/9] Fixed Notice error. Issue #185. --- src/Controller/WebhookController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 2e74c1fa..2f987039 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -605,7 +605,11 @@ class WebhookController extends Controller Project::TYPE_GIT, ]); - switch ($_SERVER['CONTENT_TYPE']) { + $contentType = !empty($_SERVER['CONTENT_TYPE']) + ? $_SERVER['CONTENT_TYPE'] + : null; + + switch ($contentType) { case 'application/x-www-form-urlencoded': $payload = json_decode($this->getParam('payload'), true); break;