Optimized how and when code coverage reports are generated for different types of tests

This commit is contained in:
Alejandro Celaya
2022-08-12 18:10:45 +02:00
parent 7377917642
commit 23f92179ad
3 changed files with 25 additions and 32 deletions

View File

@@ -28,6 +28,7 @@ use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use function file_exists;
use function Functional\contains;
use function Laminas\Stratigility\middleware;
use function Shlinkio\Shlink\Config\env;
use function sprintf;
@@ -39,7 +40,8 @@ use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT;
$isApiTest = env('TEST_ENV') === 'api';
$isCliTest = env('TEST_ENV') === 'cli';
$isE2eTest = $isApiTest || $isCliTest;
$generateCoverage = env('GENERATE_COVERAGE') === 'yes';
$coverageType = env('GENERATE_COVERAGE');
$generateCoverage = contains(['yes', 'pretty'], $coverageType);
$coverage = null;
if ($isE2eTest && $generateCoverage) {
@@ -52,7 +54,7 @@ if ($isE2eTest && $generateCoverage) {
/**
* @param 'api'|'cli' $type
*/
$exportCoverage = static function (string $type = 'api') use (&$coverage): void {
$exportCoverage = static function (string $type = 'api') use (&$coverage, $coverageType): void {
if ($coverage === null) {
return;
}
@@ -66,9 +68,12 @@ $exportCoverage = static function (string $type = 'api') use (&$coverage): void
$coverage->merge(require $covPath);
}
(new PHP())->process($coverage, $covPath);
(new Xml(Version::getVersionString()))->process($coverage, $basePath . '/coverage-xml');
(new Html())->process($coverage, $basePath . '/coverage-html');
if ($coverageType === 'pretty') {
(new Html())->process($coverage, $basePath . '/coverage-html');
} else {
(new PHP())->process($coverage, $covPath);
(new Xml(Version::getVersionString()))->process($coverage, $basePath . '/coverage-xml');
}
};
$buildDbConnection = static function (): array {