30
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-06-05 15:20:49 +00:00
tcpdf/tests/coverage.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2023-03-31 14:35:37 +00:00
<?php
if (extension_loaded('pcov')) {
\pcov\start();
class CoverageObjectPcov
{
public function __destruct()
{
\pcov\stop();
$rootDir = realpath(__DIR__ . '/../') . '/';
$coverageFile = $rootDir . 'tests/coverage.lcov';
$covData = \pcov\collect(
\pcov\exclusive,
array(
__FILE__
)
);
$coverageData = '';
foreach ($covData as $file => $coverageForFile) {
$coverageData .= 'SF:' . $file . "\n";
$coverageData .= 'TN:' . str_replace($rootDir, '', $_SERVER['PHP_SELF']) . "\n";
foreach ($coverageForFile as $line => $coverageValue) {
$coverageValue = $coverageValue === -1 ? 0 : $coverageValue;
$coverageData .= 'DA:' . $line . ',' . $coverageValue . "\n";
}
$coverageData .= 'end_of_record' . "\n";
}
file_put_contents($coverageFile, $coverageData, LOCK_EX | FILE_APPEND);
}
}
$a = new CoverageObjectPcov();
}
if (extension_loaded('xdebug')) {
\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
class CoverageObjectXdebug
{
public function __destruct()
{
$rootDir = realpath(__DIR__ . '/../') . '/';
$coverageFile = $rootDir . 'tests/coverage.lcov';
$covData = xdebug_get_code_coverage();
$coverageData = '';
foreach ($covData as $file => $coverageForFile) {
$coverageData .= 'SF:' . $file . "\n";
$coverageData .= 'TN:' . str_replace($rootDir, '', $_SERVER['PHP_SELF']) . "\n";
foreach ($coverageForFile as $line => $coverageValue) {
$coverageValue = $coverageValue > 0 ? $coverageValue : 0;
$coverageData .= 'DA:' . $line . ',' . $coverageValue . "\n";
}
$coverageData .= 'end_of_record' . "\n";
}
file_put_contents($coverageFile, $coverageData, LOCK_EX | FILE_APPEND);
\xdebug_stop_code_coverage(true);
}
}
$a = new CoverageObjectXdebug();
}