From b5f9e906fa34868203ef46a9dc5d33da4cd3e8d1 Mon Sep 17 00:00:00 2001 From: "michael.schramm" Date: Wed, 5 Nov 2014 01:15:37 +0100 Subject: [PATCH] Improved PHPSpec plugin. Now includes a UI Plugin. --- PHPCI/Plugin/PhpSpec.php | 85 ++++++++++++++++++++++- public/assets/js/build-plugins/phpspec.js | 80 +++++++++++++++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 public/assets/js/build-plugins/phpspec.js diff --git a/PHPCI/Plugin/PhpSpec.php b/PHPCI/Plugin/PhpSpec.php index 181c67e9..7fbc332e 100644 --- a/PHPCI/Plugin/PhpSpec.php +++ b/PHPCI/Plugin/PhpSpec.php @@ -58,10 +58,91 @@ class PhpSpec implements PHPCI\Plugin return false; } - $success = $this->phpci->executeCommand($phpspec . ' --format=pretty --no-code-generation run'); + $success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run'); + $output = $this->phpci->getLastOutput(); chdir($curdir); - + + /* + * process xml output + * + * + * + * + * + * attributes(); + $data = array( + 'time' => (float)$attr['time'], + 'tests' => (int)$attr['tests'], + 'failures' => (int)$attr['failures'], + 'errors' => (int)$attr['errors'], + + // now all the tests + 'suites' => array() + ); + + /** + * @var \SimpleXMLElement $group + */ + foreach ($xml->xpath('testsuite') as $group) { + $attr = $group->attributes(); + $suite = array( + 'name' => (String)$attr['name'], + 'time' => (float)$attr['time'], + 'tests' => (int)$attr['tests'], + 'failures' => (int)$attr['failures'], + 'errors' => (int)$attr['errors'], + 'skipped' => (int)$attr['skipped'], + + // now the cases + 'cases' => array() + ); + + /** + * @var \SimpleXMLElement $child + */ + foreach ($group->xpath('testcase') as $child) { + $attr = $child->attributes(); + $case = array( + 'name' => (String)$attr['name'], + 'classname' => (String)$attr['classname'], + 'time' => (float)$attr['time'], + 'status' => (String)$attr['status'], + ); + + if ($case['status']=='failed') { + $error = array(); + /* + * ok, sad, we had an error + * + * there should be one - foreach makes this easier + */ + foreach ($child->xpath('failure') as $failure) { + $attr = $failure->attributes(); + $error['type'] = (String)$attr['type']; + $error['message'] = (String)$attr['message']; + } + + foreach ($child->xpath('system-err') as $system_err) { + $error['raw'] = (String)$system_err; + } + + $case['error'] = $error; + } + + $suite['cases'][] = $case; + } + + $data['suites'][] = $suite; + } + + $this->build->storeMeta('phpspec', $data); + + return $success; } } diff --git a/public/assets/js/build-plugins/phpspec.js b/public/assets/js/build-plugins/phpspec.js new file mode 100644 index 00000000..be7ac7b9 --- /dev/null +++ b/public/assets/js/build-plugins/phpspec.js @@ -0,0 +1,80 @@ +var phpspecPlugin = PHPCI.UiPlugin.extend({ + id: 'build-phpspec-errors', + css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12', + title: 'PHPSpec', + lastData: null, + displayOnUpdate: false, + box: true, + rendered: false, + + register: function() { + var self = this; + var query = PHPCI.registerQuery('phpspec', -1, {key: 'phpspec'}) + + $(window).on('phpspec', function(data) { + self.onUpdate(data); + }); + + $(window).on('build-updated', function() { + if (!self.rendered) { + self.displayOnUpdate = true; + query(); + } + }); + }, + + render: function() { + + return $('' + + '' + + '' + + ' ' + + ' ' + + ' ' + + '' + + '
SuiteTestResult
'); + }, + + onUpdate: function(e) { + if (!e.queryData) { + $('#build-phpspec-errors').hide(); + return; + } + + this.rendered = true; + this.lastData = e.queryData; + + var tests = this.lastData[0].meta_value; + var tbody = $('#phpspec-data tbody'); + tbody.empty(); + + for (var i in tests.suites) { + var test_suite = tests.suites[i]; + + for(var k in test_suite.cases){ + var test_case = test_suite.cases[k]; + + var row = $( + ''+ + ''+test_suite.name+''+ + ''+test_case.name+''+ + ''+(test_case.message?test_case.message:'OK')+''+ + '' + ); + + if (test_case.status!='passed') { + row.addClass('danger'); + } else { + row.addClass('success'); + } + + tbody.append(row); + } + } + + // show plugin once preparation of grid is done + $('#build-phpspec-errors').show(); + } +}); + +PHPCI.registerPlugin(new phpspecPlugin());