diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 5f21d3dc..da767727 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -184,6 +184,7 @@ PHPCI', 'phpspec' => 'PHP Spec', 'phpunit' => 'PHP Unit', 'technical_debt' => 'Technical Debt', + 'behat' => 'Behat', 'file' => 'File', 'line' => 'Line', diff --git a/PHPCI/Plugin/Behat.php b/PHPCI/Plugin/Behat.php index 0e2fe69b..ad2956b4 100644 --- a/PHPCI/Plugin/Behat.php +++ b/PHPCI/Plugin/Behat.php @@ -66,12 +66,64 @@ class Behat implements \PHPCI\Plugin if (!$behat) { $this->phpci->logFailure(Lang::get('could_not_find', 'behat')); + return false; } $success = $this->phpci->executeCommand($behat . ' %s', $this->features); chdir($curdir); + list($errorCount, $data) = $this->parseBehatOutput(); + + $this->build->storeMeta('behat-warnings', $errorCount); + $this->build->storeMeta('behat-data', $data); + return $success; } + + /** + * Parse the behat output and return details on failures + * + * @return array + */ + public function parseBehatOutput() + { + $output = $this->phpci->getLastOutput(); + + $parts = explode('---', $output); + + if (count($parts) <= 1) { + return array(0, array()); + } + + $lines = explode(PHP_EOL, $parts[1]); + + $errorCount = 0; + $storeFailures = false; + $data = []; + + foreach ($lines as $line) { + $line = trim($line); + if ($line == 'Failed scenarios:') { + $storeFailures = true; + continue; + } + + if (strpos($line, ':') === false) { + $storeFailures = false; + } + + if ($storeFailures) { + $lineParts = explode(':', $line); + $data[] = array( + 'file' => $lineParts[0], + 'line' => $lineParts[1] + ); + } + } + + $errorCount = count($data); + + return array($errorCount, $data); + } } diff --git a/PHPCI/Plugin/TechnicalDebt.php b/PHPCI/Plugin/TechnicalDebt.php index fed76566..c10e7d29 100755 --- a/PHPCI/Plugin/TechnicalDebt.php +++ b/PHPCI/Plugin/TechnicalDebt.php @@ -202,7 +202,5 @@ class TechnicalDebt implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin } } } - - return array($errorCount, $data); } } diff --git a/public/assets/js/build-plugins/behat.js b/public/assets/js/build-plugins/behat.js new file mode 100644 index 00000000..4140a267 --- /dev/null +++ b/public/assets/js/build-plugins/behat.js @@ -0,0 +1,74 @@ +var BehatPlugin = ActiveBuild.UiPlugin.extend({ + id: 'build-behat', + css: 'col-lg-6 col-md-12 col-sm-12 col-xs-12', + title: Lang.get('behat'), + lastData: null, + box: true, + rendered: false, + + register: function() { + var self = this; + var query = ActiveBuild.registerQuery('behat-data', -1, {key: 'behat-data'}) + + $(window).on('behat-data', function(data) { + self.onUpdate(data); + }); + + $(window).on('build-updated', function() { + if (!self.rendered) { + query(); + } + }); + }, + + render: function() { + return $('
' + + '' + + '' + + ' ' + + ' ' + + '' + + '
'+Lang.get('file')+''+Lang.get('line')+'
'); + }, + + onUpdate: function(e) { + if (!e.queryData) { + $('#build-behat').hide(); + return; + } + + this.rendered = true; + this.lastData = e.queryData; + + var errors = this.lastData[0].meta_value; + var tbody = $('#behat-data tbody'); + tbody.empty(); + + if (errors.length == 0) { + $('#build-behat').hide(); + return; + } + + for (var i in errors) { + var file = errors[i].file; + + if (ActiveBuild.fileLinkTemplate) { + var fileLink = ActiveBuild.fileLinkTemplate.replace('{FILE}', file); + fileLink = fileLink.replace('{LINE}', errors[i].line); + + file = '' + file + ''; + } + + var row = $('' + + ''+file+'' + + ''+errors[i].line+'' + + ''); + + tbody.append(row); + } + + $('#build-behat').show(); + } +}); + +ActiveBuild.registerPlugin(new BehatPlugin());