Added PHPUnit code coverage log output and chart in information tab.

Issue #148.
This commit is contained in:
Dmitry Khomutov 2018-02-25 10:41:59 +07:00
commit c5ce085371
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
8 changed files with 147 additions and 9 deletions

View file

@ -199,12 +199,15 @@ PHP Censor',
'chart_display' => 'This chart will display once the build has completed.',
'build' => 'Build',
'lines' => 'Lines',
'build' => 'Build',
'lines' => 'Lines',
'classes' => 'Classes',
'methods' => 'Methods',
'comment_lines' => 'Comment lines',
'noncomment_lines' => 'Non-Comment lines',
'logical_lines' => 'Logical Lines',
'lines_of_code' => 'Lines of code',
'coverage' => 'PHPUnit code coverage',
'build_log' => 'Build log',
'quality_trend' => 'Quality trend',
'codeception_errors' => 'Codeception errors',

View file

@ -192,12 +192,15 @@ PHP Censor',
'chart_display' => 'Этот график будет показан после окончания сборки.',
'build' => 'Сборка',
'lines' => 'Строк',
'build' => 'Сборка',
'lines' => 'Строк',
'classes' => 'Классов',
'methods' => 'Методов',
'comment_lines' => 'Строк комментариев',
'noncomment_lines' => 'Строк некомментариев',
'logical_lines' => 'Строк логики',
'lines_of_code' => 'Строк кода',
'coverage' => 'Покрытие кода тестами PHPUnit',
'build_log' => 'Лог сборки',
'quality_trend' => 'Тенденция качества',
'codeception_errors' => 'Ошибки Codeception',

View file

@ -121,6 +121,7 @@ class PhpUnitOptions
*/
if (isset($this->options['coverage']) && $this->options['coverage']) {
$this->addArgument('coverage-html', $this->location);
$this->addArgument('coverage-text');
}
/*
@ -141,7 +142,7 @@ class PhpUnitOptions
* @param string $argumentName
* @param string $argumentValue
*/
public function addArgument($argumentName, $argumentValue)
public function addArgument($argumentName, $argumentValue = null)
{
if (isset($this->arguments[$argumentName])) {
if (!is_array($this->arguments[$argumentName])) {

View file

@ -136,7 +136,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
// Save the results into a log file
$logFile = @tempnam($buildPath, 'jLog_');
$options->addArgument('log-'.$logFormat, $logFile);
$options->addArgument('log-' . $logFormat, $logFile);
// Removes any current configurations files
$options->removeArgument('configuration');
@ -152,12 +152,25 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
$arguments = $this->builder->interpolate($options->buildArgumentString());
$cmd = $this->findBinary('phpunit') . ' %s %s';
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
$output = $this->builder->getLastOutput();
$this->processResults($logFile, $logFormat);
$config = $this->builder->getSystemConfig('php-censor');
if ($options->getOption('coverage')) {
preg_match(
'#Classes:[\s]*(.*?)%[^M]*?Methods:[\s]*(.*?)%[^L]*?Lines:[\s]*(.*?)\%#s',
$output,
$matches
);
$this->build->storeMeta('phpunit-coverage', [
'classes' => !empty($matches[1]) ? $matches[1] : '0.00',
'methods' => !empty($matches[2]) ? $matches[2] : '0.00',
'lines' => !empty($matches[3]) ? $matches[3] : '0.00',
]);
$this->builder->logSuccess(
sprintf(
"\nPHPUnit successful.\nYou can use coverage report: %s",
@ -190,7 +203,10 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
$this->build->storeMeta('phpunit-errors', $parser->getFailures());
foreach ($parser->getErrors() as $error) {
$severity = $error['severity'] == $parser::SEVERITY_ERROR ? BuildError::SEVERITY_CRITICAL : BuildError::SEVERITY_HIGH;
$severity = $error['severity'] ==
$parser::SEVERITY_ERROR ?
BuildError::SEVERITY_CRITICAL :
BuildError::SEVERITY_HIGH;
$this->build->reportError(
$this->builder, 'php_unit', $error['message'], $severity, $error['file'], $error['line']
);

View file

@ -140,8 +140,9 @@ class PhpUnitResultJson extends PhpUnitResult
/**
* Saves additional info for a failing test
*
* @param array $data
* @param array $event
*
* @return array
*/
protected function getFileAndLine($event)
{