diff --git a/PHPCI/Languages/lang.da.php b/PHPCI/Languages/lang.da.php index 12ed31e2..5010f28e 100644 --- a/PHPCI/Languages/lang.da.php +++ b/PHPCI/Languages/lang.da.php @@ -166,6 +166,7 @@ Services sektionen under dit Bitbucket-repository.', 'lines_of_code' => 'Kode-linjer', 'build_log' => 'Build-log', 'quality_trend' => 'Kvalitets-trend', + 'codeception_errors' => 'Codeception-fejl', 'phpmd_warnings' => 'PHPMD-advarsler', 'phpcs_warnings' => 'PHPCS-advarsler', 'phpcs_errors' => 'PHPCS-fejl', @@ -174,6 +175,7 @@ Services sektionen under dit Bitbucket-repository.', 'phpdoccheck_warnings' => 'Manglende Docblocks', 'issues' => 'Sager', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Manglende Docblocks', diff --git a/PHPCI/Languages/lang.de.php b/PHPCI/Languages/lang.de.php index d89261c8..c40ef23d 100644 --- a/PHPCI/Languages/lang.de.php +++ b/PHPCI/Languages/lang.de.php @@ -164,6 +164,7 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab 'lines_of_code' => 'Anzahl Codezeilen', 'build_log' => 'Buildprotokoll', 'quality_trend' => 'Qualitätstrend', + 'codeception_errors' => 'Codeception Errors', 'phpmd_warnings' => 'PHPMD Warnings', 'phpcs_warnings' => 'PHPCS Warnings', 'phpcs_errors' => 'PHPCS Errors', @@ -172,6 +173,7 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab 'phpdoccheck_warnings' => 'Fehlende Docblocks', 'issues' => 'Probleme', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Fehlende Docblocks', diff --git a/PHPCI/Languages/lang.el.php b/PHPCI/Languages/lang.el.php index 2089cd04..c611a87d 100644 --- a/PHPCI/Languages/lang.el.php +++ b/PHPCI/Languages/lang.el.php @@ -166,6 +166,7 @@ Services του Bitbucket αποθετηρίου σας.', 'lines_of_code' => 'Γραμμές Κώδικα', 'build_log' => 'Αρχείο καταγραφής κατασκευών', 'quality_trend' => 'Ποιότητα τρέντ', + 'codeception_errors' => 'Λάθη Codeception', 'phpmd_warnings' => 'Προειδοποιήσεις PHPMD', 'phpcs_warnings' => 'Προειδοποιήσεις PHPCS ', 'phpcs_errors' => 'Λάθη PHPCS', @@ -174,6 +175,7 @@ Services του Bitbucket αποθετηρίου σας.', 'phpdoccheck_warnings' => 'Χαμένα Docblocks', 'issues' => 'Θέματα', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Ανιχνευτής Αντιγραφής/Επικόλλησης', 'phpcs' => 'Sniffer Κώδικα PHP', 'phpdoccheck' => 'Χαμένα Docblocks', diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 41526624..9718e442 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -167,6 +167,7 @@ PHPCI', 'lines_of_code' => 'Lines of Code', 'build_log' => 'Build Log', 'quality_trend' => 'Quality Trend', + 'codeception_errors' => 'Codeception Errors', 'phpmd_warnings' => 'PHPMD Warnings', 'phpcs_warnings' => 'PHPCS Warnings', 'phpcs_errors' => 'PHPCS Errors', @@ -175,6 +176,7 @@ PHPCI', 'phpdoccheck_warnings' => 'Missing Docblocks', 'issues' => 'Issues', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Missing Docblocks', diff --git a/PHPCI/Languages/lang.fr.php b/PHPCI/Languages/lang.fr.php index 9e7cd339..45cc3958 100644 --- a/PHPCI/Languages/lang.fr.php +++ b/PHPCI/Languages/lang.fr.php @@ -167,6 +167,7 @@ PHPCI', 'lines_of_code' => 'Lignes de code', 'build_log' => 'Log du build', 'quality_trend' => 'Tendance de la qualité', + 'codeception_errors' => 'Erreurs Codeception', 'phpmd_warnings' => 'Alertes PHPMD', 'phpcs_warnings' => 'Alertes PHPCS', 'phpcs_errors' => 'Erreurs PHPCS', @@ -175,6 +176,7 @@ PHPCI', 'phpdoccheck_warnings' => 'Blocs de documentation manquants', 'issues' => 'Tickets', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Missing Docblocks', diff --git a/PHPCI/Languages/lang.it.php b/PHPCI/Languages/lang.it.php index e4b531e0..c5c4e01b 100644 --- a/PHPCI/Languages/lang.it.php +++ b/PHPCI/Languages/lang.it.php @@ -11,7 +11,7 @@ $strings = array( 'language_name' => 'Italiano', 'language' => 'Lingua', - + // Log in: 'log_in_to_phpci' => 'Accedi a PHPCI', 'login_error' => 'Indirizzo email o password errati', @@ -169,6 +169,7 @@ PHPCI', 'lines_of_code' => 'Linee di codice', 'build_log' => 'Log della build', 'quality_trend' => 'Trend della qualità', + 'codeception_errors' => 'Errori di Codeception', 'phpmd_warnings' => 'Avvisi di PHPMD', 'phpcs_warnings' => 'Avvisi di PHPCS', 'phpcs_errors' => 'Errori di PHPCS', @@ -177,6 +178,7 @@ PHPCI', 'phpdoccheck_warnings' => 'Docblocks mancanti', 'issues' => 'Segnalazioni', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Docblocks mancanti', diff --git a/PHPCI/Languages/lang.nl.php b/PHPCI/Languages/lang.nl.php index e03e709f..f38272c4 100644 --- a/PHPCI/Languages/lang.nl.php +++ b/PHPCI/Languages/lang.nl.php @@ -167,6 +167,7 @@ Services sectie van je Bitbucket repository toegevoegd worden.', 'lines_of_code' => 'Lijnen code', 'build_log' => 'Build Log', 'quality_trend' => 'Kwaliteitstrend', + 'codeception_errors' => 'Codeception Fouten', 'phpmd_warnings' => 'PHPMD Waarschuwingen', 'phpcs_warnings' => 'PHPCS Waarschuwingen', 'phpcs_errors' => 'PHPCS Fouten', @@ -175,6 +176,7 @@ Services sectie van je Bitbucket repository toegevoegd worden.', 'phpdoccheck_warnings' => 'Ontbrekende Docblocks', 'issues' => 'Problemen', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Ontbrekende Docblocks', diff --git a/PHPCI/Languages/lang.pl.php b/PHPCI/Languages/lang.pl.php index a614d29d..4aafc9cf 100644 --- a/PHPCI/Languages/lang.pl.php +++ b/PHPCI/Languages/lang.pl.php @@ -167,6 +167,7 @@ Services repozytoria Bitbucket.', 'lines_of_code' => 'Linie Kodu', 'build_log' => 'Log Budowania', 'quality_trend' => 'Trend Jakości', + 'codeception_errors' => 'Błędy Codeception', 'phpmd_warnings' => 'Alerty PHPMD', 'phpcs_warnings' => 'Alerty PHPCS', 'phpcs_errors' => 'Błędy PHPCS', @@ -175,6 +176,7 @@ Services repozytoria Bitbucket.', 'phpdoccheck_warnings' => 'Brakuje sekcji DocBlock', 'issues' => 'Problemy', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Brakuje sekcji DocBlock', diff --git a/PHPCI/Languages/lang.ru.php b/PHPCI/Languages/lang.ru.php index dfef84d9..00b2783e 100644 --- a/PHPCI/Languages/lang.ru.php +++ b/PHPCI/Languages/lang.ru.php @@ -162,6 +162,7 @@ PHPCI', 'lines_of_code' => 'Строк кода', 'build_log' => 'Лог сборки', 'quality_trend' => 'Тенденция качества', + 'codeception_errors' => 'Ошибки Codeception', 'phpmd_warnings' => 'Предупреждения PHPMD', 'phpcs_warnings' => 'Предупреждения PHPCS', 'phpcs_errors' => 'Ошибки PHPCS', @@ -170,6 +171,7 @@ PHPCI', 'phpdoccheck_warnings' => 'Пропущенные Docblocks', 'issues' => 'Проблемы', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Missing Docblocks', diff --git a/PHPCI/Languages/lang.uk.php b/PHPCI/Languages/lang.uk.php index 24f9cbb2..f51bd885 100644 --- a/PHPCI/Languages/lang.uk.php +++ b/PHPCI/Languages/lang.uk.php @@ -167,14 +167,16 @@ PHPCI', 'lines_of_code' => 'Рядки коду', 'build_log' => 'Лог збірки', 'quality_trend' => 'Тенденція якості', + 'codeception_errors' => 'Помилки Codeception', 'phpmd_warnings' => 'Попередження PHPMD', 'phpcs_warnings' => 'Попередження PHPCS', 'phpcs_errors' => 'Помилки PHPCS', 'phplint_errors' => 'Помилки Lint', - 'phpunit_errors' => 'Помилки PHPCS', + 'phpunit_errors' => 'Помилки PHPUnit', 'phpdoccheck_warnings' => 'Відсутні Docblocks', 'issues' => 'Проблеми', + 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Відсутні Docblocks', diff --git a/PHPCI/Plugin/Codeception.php b/PHPCI/Plugin/Codeception.php index 2f9e66fd..7d7fd81e 100644 --- a/PHPCI/Plugin/Codeception.php +++ b/PHPCI/Plugin/Codeception.php @@ -9,37 +9,50 @@ namespace PHPCI\Plugin; +use PHPCI; use PHPCI\Builder; use PHPCI\Helper\Lang; use PHPCI\Model\Build; +use PHPCI\Plugin\Util\TapParser; /** - * Codeception Plugin - Enables full acceptance, unit, and functional testing. + * Codeception Plugin - Enables full acceptance, unit, and functional testing + * * @author Don Gilbert + * @author Igor Timoshenko * @package PHPCI * @subpackage Plugins */ -class Codeception implements \PHPCI\Plugin +class Codeception implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin { /** * @var string */ protected $args = ''; + /** + * @var Build + */ + protected $build; + /** * @var Builder */ protected $phpci; - protected $build; + /** + * @var string|string[] The path (or array of paths) of an yml config for Codeception + */ + protected $configFile; /** - * @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit + * @var string The path where the reports and logs are stored */ - protected $xmlConfigFile; + protected $logPath = 'tests/_output'; /** * Set up the plugin, configure options, etc. + * * @param Builder $phpci * @param Build $build * @param array $options @@ -50,49 +63,86 @@ class Codeception implements \PHPCI\Plugin $this->build = $build; if (isset($options['config'])) { - $this->xmlConfigFile = $options['config']; + $this->configFile = $options['config']; } + if (isset($options['args'])) { $this->args = (string) $options['args']; } + + if (isset($options['log_path'])) { + $this->logPath = $options['log_path']; + } } /** - * Runs Codeception tests, optionally using specified config file(s). + * {@inheritDoc} */ public function execute() { $success = true; - // Run any config files first. This can be either a single value or an array. - if ($this->xmlConfigFile !== null) { - $success &= $this->runConfigFile($this->xmlConfigFile); + $this->phpci->logExecOutput(false); + + // Run any config files first. This can be either a single value or an array + if ($this->configFile !== null) { + $success &= $this->runConfigFile($this->configFile); } + $tapString = file_get_contents( + $this->phpci->buildPath . $this->logPath . DIRECTORY_SEPARATOR . 'report.tap.log' + ); + + try { + $tapParser = new TapParser($tapString); + $output = $tapParser->parse(); + } catch (\Exception $ex) { + $this->phpci->logFailure($tapString); + + throw $ex; + } + + $failures = $tapParser->getTotalFailures(); + + $this->build->storeMeta('codeception-errors', $failures); + $this->build->storeMeta('codeception-data', $output); + + $this->phpci->logExecOutput(true); + return $success; } /** - * Run tests from a Codeception config file. - * @param $configPath + * {@inheritDoc} + */ + public static function canExecute($stage, Builder $builder, Build $build) + { + return $stage === 'test'; + } + + /** + * Run tests from a Codeception config file + * + * @param string $configPath * @return bool|mixed */ protected function runConfigFile($configPath) { if (is_array($configPath)) { - return $this->recurseArg($configPath, array($this, "runConfigFile")); + return $this->recurseArg($configPath, array($this, 'runConfigFile')); } else { - $codecept = $this->phpci->findBinary('codecept'); if (!$codecept) { $this->phpci->logFailure(Lang::get('could_not_find', 'codecept')); + return false; } - $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" '. $this->args; + $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --tap ' . $this->args; + if (IS_WIN) { - $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" '. $this->args; + $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" --tap ' . $this->args; } $configPath = $this->phpci->buildPath . $configPath; @@ -103,16 +153,18 @@ class Codeception implements \PHPCI\Plugin } /** - * @param $array - * @param $callable + * @param array $array + * @param \Callback $callable * @return bool|mixed */ - protected function recurseArg($array, $callable) + protected function recurseArg(array $array, $callable) { $success = true; + foreach ($array as $subItem) { $success &= call_user_func($callable, $subItem); } + return $success; } } diff --git a/public/assets/js/build-plugins/codeception.js b/public/assets/js/build-plugins/codeception.js new file mode 100644 index 00000000..def42330 --- /dev/null +++ b/public/assets/js/build-plugins/codeception.js @@ -0,0 +1,75 @@ +var codeceptionPlugin = ActiveBuild.UiPlugin.extend({ + id: 'build-codeception-errors', + css: 'col-lg-6 col-md-12 col-sm-12 col-xs-12', + title: Lang.get('codeception'), + lastData: null, + displayOnUpdate: false, + box: true, + rendered: false, + + register: function() { + var self = this; + var query = ActiveBuild.registerQuery('codeception-data', -1, {key: 'codeception-data'}) + + $(window).on('codeception-data', function(data) { + self.onUpdate(data); + }); + + $(window).on('build-updated', function() { + if (!self.rendered) { + self.displayOnUpdate = true; + query(); + } + }); + }, + + render: function() { + + return $('' + + '' + + '' + + ' ' + + '' + + '
'+Lang.get('test')+'
'); + }, + + onUpdate: function(e) { + if (!e.queryData) { + $('#build-codeception-errors').hide(); + return; + } + + this.rendered = true; + this.lastData = e.queryData; + + var tests = this.lastData[0].meta_value; + var tbody = $('#codeception-data tbody'); + tbody.empty(); + + if (tests.length == 0) { + $('#build-codeception-errors').hide(); + return; + } + + for (var i in tests) { + + var row = $('' + + ''+tests[i].suite+'' + + '::'+tests[i].test+'
' + + ''+(tests[i].message || '')+'' + + ''); + + if (!tests[i].pass) { + row.addClass('danger'); + } else { + row.addClass('success'); + } + + tbody.append(row); + } + + $('#build-codeception-errors').show(); + } +}); + +ActiveBuild.registerPlugin(new codeceptionPlugin()); diff --git a/public/assets/js/build-plugins/warnings.js b/public/assets/js/build-plugins/warnings.js index a2a31dc3..7e8ae0b1 100644 --- a/public/assets/js/build-plugins/warnings.js +++ b/public/assets/js/build-plugins/warnings.js @@ -3,6 +3,7 @@ var warningsPlugin = ActiveBuild.UiPlugin.extend({ css: 'col-lg-6 col-md-6 col-sm-12 col-xs-12', title: Lang.get('quality_trend'), keys: { + 'codeception-errors': Lang.get('codeception_errors'), 'phpmd-warnings': Lang.get('phpmd_warnings'), 'phpcs-warnings': Lang.get('phpcs_warnings'), 'phpcs-errors': Lang.get('phpcs_errors'), @@ -24,7 +25,7 @@ var warningsPlugin = ActiveBuild.UiPlugin.extend({ queries.push(ActiveBuild.registerQuery(key, -1, {num_builds: 10, key: key})); } - $(window).on('phpmd-warnings phpcs-warnings phptallint-warnings phptallint-errors phpcs-errors phplint-errors phpunit-errors phpdoccheck-warnings', function(data) { + $(window).on('codeception-errors phpmd-warnings phpcs-warnings phptallint-warnings phptallint-errors phpcs-errors phplint-errors phpunit-errors phpdoccheck-warnings', function(data) { self.onUpdate(data); });