Permalink
Browse files

Code coverage analysis added to tests.

Small tweaks for builder tests.
  • Loading branch information...
nazar-pc committed Jun 26, 2016
1 parent 50d4ba2 commit dac3306a0492444c53b08c40621544f182b27eb9
@@ -1,9 +1,12 @@
# Do not commit configuration
# Exclude configuration
config/main.json
# Do not commit files from storage directory
# Exclude files from storage directory
storage/*/*
# Except .htaccess, which should be committed
!storage/*/.htaccess
# Exclude backups, they are just for investigations in case when update failed
fs_backup.json
meta_backup.json
# Exclude test coverage results
tests/coverage_data.json
tests/code_coverage_report/*
@@ -26,3 +26,10 @@ script:
- php -d variables_order=EGPCS phpt-tests-runner tests
after_success:
- php -d variables_order=EGPCS -d phar.readonly=Off ci/upload_build.php
after_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.0' ]; then
php tests/code_coverage_report.php
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover tests/code_coverage_report/clover.xml
fi
@@ -0,0 +1,17 @@
<?php
if (!isset($argv[1])) {
die("First argument MUST point to vendor directory after `composer require phpunit/php-code-coverage`, resulting `php-code-coverage.phar` will be created in current directory\n");
}
$phar = new Phar('php-code-coverage.phar');
$phar->startBuffering();
$phar->buildFromDirectory($argv[1]);
$phar->setStub(
/** @lang PHP */
<<<STUB
<?php
Phar::mapPhar('php-code-coverage.phar');
require_once 'phar://php-code-coverage.phar/autoload.php';
__HALT_COMPILER();
STUB
);
$phar->stopBuffering();
@@ -26,3 +26,5 @@
if (!defined('DEBUG')) {
define('DEBUG', false);
}
require_once __DIR__.'/code_coverage.php';
@@ -0,0 +1,35 @@
<?php
/**
* @package CleverStyle Framework
* @subpackage Test
* @author Nazar Mokrynskyi <nazar@mokrynskyi.com>
* @copyright Copyright (c) 2016, Nazar Mokrynskyi
* @license MIT License, see license.txt
*/
if (!extension_loaded('xdebug')) {
return;
}
require_once __DIR__.'/php-code-coverage.phar';
$filter = new \SebastianBergmann\CodeCoverage\Filter;
$filter->addDirectoryToWhitelist(__DIR__.'/../build');
$filter->addDirectoryToWhitelist(__DIR__.'/../components/modules/System');
$filter->addDirectoryToWhitelist(__DIR__.'/../core');
$filter->addDirectoryToWhitelist(__DIR__.'/cscms.travis');
$filter->removeDirectoryFromWhitelist(__DIR__.'/../core/thirdparty');
$coverage_data_location = __DIR__.'/coverage_data.json';
$coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage(null, $filter);
if (file_exists($coverage_data_location)) {
$coverage->setData(file_get_json($coverage_data_location));
}
$coverage->start($_ENV['TEST_FILE']);
register_shutdown_function(
function () use ($coverage, $coverage_data_location) {
$coverage->stop();
file_put_json($coverage_data_location, $coverage->getData(true));
}
);
@@ -0,0 +1,54 @@
<?php
/**
* @package CleverStyle Framework
* @subpackage Test
* @author Nazar Mokrynskyi <nazar@mokrynskyi.com>
* @copyright Copyright (c) 2016, Nazar Mokrynskyi
* @license MIT License, see license.txt
*/
require_once __DIR__.'/php-code-coverage.phar';
$filter = new \SebastianBergmann\CodeCoverage\Filter;
$filter->addDirectoryToWhitelist(__DIR__.'/../build');
$filter->addDirectoryToWhitelist(__DIR__.'/../components/modules/System');
$filter->addDirectoryToWhitelist(__DIR__.'/../core');
$filter->addDirectoryToWhitelist(__DIR__.'/cscms.travis');
$filter->removeDirectoryFromWhitelist(__DIR__.'/../core/thirdparty');
$coverage_data_location = __DIR__.'/coverage_data.json';
$coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage(null, $filter);
$coverage->setAddUncoveredFilesFromWhitelist(true);
$data = json_decode(file_get_contents($coverage_data_location), true);
$normal_prefix = realpath(__DIR__.'/..');
$installed_prefix = __DIR__.'/cscms.travis';
foreach ($data as $file => $d) {
if (strpos($file, $installed_prefix) === 0) {
$new_file = $normal_prefix.substr($file, strlen($installed_prefix));
if (isset($data[$new_file])) {
$lines = array_unique(
array_merge(
array_keys($data[$new_file]),
array_keys($d)
)
);
foreach ($data[$new_file] as $line => $calls) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$data[$new_file][$line] = array_merge(@$data[$new_file][$line] ?: [], @$d[$line] ?: []);
}
} else {
$data[$new_file] = $d;
}
unset($data[$file]);
}
}
$coverage->setData($data);
$report_location = __DIR__.'/code_coverage_report';
exec("rm -rf ".escapeshellarg($report_location));
$html_report = new \SebastianBergmann\CodeCoverage\Report\Html\Facade;
@$html_report->process($coverage, $report_location);
$clover_report = new \SebastianBergmann\CodeCoverage\Report\Clover;
@$clover_report->process($coverage, "$report_location/clover.xml");
unlink($coverage_data_location);
Binary file not shown.
@@ -20,4 +20,4 @@ Done! CleverStyle Framework %s+build-%d
--CLEAN--
<?php
$version = json_decode(file_get_contents(__DIR__.'/../../../components/modules/System/meta.json'), true)['version'];
unlink(__DIR__."/../../CleverStyle_Framework_$version.phar.php");
unlink(__DIR__."/../../../CleverStyle_Framework_$version.phar.php");
@@ -20,4 +20,4 @@ Done! CleverStyle Framework %s+build-%d
--CLEAN--
<?php
$version = json_decode(file_get_contents(__DIR__.'/../../../components/modules/System/meta.json'), true)['version'];
unlink(__DIR__."/../../CleverStyle_Framework_$version.phar.php");
unlink(__DIR__."/../../../CleverStyle_Framework_$version.phar.php");
@@ -20,4 +20,4 @@ Done! CleverStyle Framework %s+build-%d
--CLEAN--
<?php
$version = json_decode(file_get_contents(__DIR__.'/../../../components/modules/System/meta.json'), true)['version'];
unlink(__DIR__."/../../CleverStyle_Framework_{$version}_Core.phar.php");
unlink(__DIR__."/../../../CleverStyle_Framework_{$version}_Core.phar.php");
@@ -6,6 +6,10 @@
require_once "$root/core/classes/h/Base.php";
require_once "$root/core/classes/h.php";
require_once "$root/core/thirdparty/upf.php";
require_once "$root/core/functions.php";
require_once "$root/tests/code_coverage.php";
if (is_dir($target)) {
exec("rm -r $target");
}
@@ -18,3 +18,5 @@
if (!defined('DEBUG')) {
define('DEBUG', false);
}
require_once __DIR__.'/code_coverage.php';

0 comments on commit dac3306

Please sign in to comment.