forked from sebastianbergmann/php-code-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXdebug3DriverTest.php
More file actions
121 lines (94 loc) · 3.46 KB
/
Copy pathXdebug3DriverTest.php
File metadata and controls
121 lines (94 loc) · 3.46 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Driver;
use const PHP_SAPI;
use function extension_loaded;
use function ini_get;
use function phpversion;
use function version_compare;
use function xdebug_code_coverage_started;
use function xdebug_get_code_coverage;
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\TestCase;
final class Xdebug3DriverTest extends TestCase
{
protected function setUp(): void
{
if (PHP_SAPI !== 'cli') {
$this->markTestSkipped('This test requires the PHP commandline interpreter');
}
if (!extension_loaded('xdebug')) {
$this->markTestSkipped('This test requires the Xdebug extension to be loaded');
}
if (version_compare(phpversion('xdebug'), '3', '<')) {
$this->markTestSkipped('This test requires version 3 of the Xdebug extension to be loaded');
}
if (!ini_get('xdebug.mode') || ini_get('xdebug.mode') !== 'coverage') {
$this->markTestSkipped('This test requires the Xdebug extension\'s code coverage functionality to be enabled');
}
if (!xdebug_code_coverage_started()) {
$this->markTestSkipped('This test requires code coverage data collection using Xdebug to be active');
}
}
public function testSupportsBranchAndPathCoverage(): void
{
$this->assertTrue($this->driver()->canCollectBranchAndPathCoverage());
}
public function testBranchAndPathCoverageCanBeDisabled(): void
{
$driver = $this->driver();
$driver->disableBranchAndPathCoverage();
$this->assertFalse($driver->collectsBranchAndPathCoverage());
}
public function testBranchAndPathCoverageCanBeEnabled(): void
{
$driver = $this->driver();
$driver->enableBranchAndPathCoverage();
$this->assertTrue($driver->collectsBranchAndPathCoverage());
}
public function testBranchAndPathCoverageIsNotCollectedByDefault(): void
{
$this->assertFalse($this->driver()->collectsBranchAndPathCoverage());
}
public function testSupportsDeadCodeDetection(): void
{
$this->assertTrue($this->driver()->canDetectDeadCode());
}
public function testDeadCodeDetectionCanBeDisabled(): void
{
$driver = $this->driver();
$driver->disableDeadCodeDetection();
$this->assertFalse($driver->detectsDeadCode());
}
public function testDeadCodeDetectionCanBeEnabled(): void
{
$driver = $this->driver();
$driver->enableDeadCodeDetection();
$this->assertTrue($driver->detectsDeadCode());
}
public function testDeadCodeIsNotDetectedByDefault(): void
{
$this->assertFalse($this->driver()->detectsDeadCode());
}
public function testHasNameAndVersion(): void
{
$this->assertStringMatchesFormat('Xdebug %s', $this->driver()->nameAndVersion());
}
public function testFilterWorks(): void
{
$bankAccount = TEST_FILES_PATH . 'BankAccount.php';
require $bankAccount;
$this->assertArrayNotHasKey($bankAccount, xdebug_get_code_coverage());
}
private function driver(): Xdebug3Driver
{
return new Xdebug3Driver(new Filter);
}
}