File: coverage.php

package info (click to toggle)
tcpdf 6.10.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,784 kB
  • sloc: php: 53,085; sh: 333; makefile: 12
file content (66 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?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();
}