1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DoyoUserBundle project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Doyo\Behat\Coverage\Bridge; |
15
|
|
|
|
16
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
17
|
|
|
use SebastianBergmann\CodeCoverage\Version; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Utility class to load driver by php-code-coverage version. |
21
|
|
|
*/ |
22
|
|
|
class Compat |
23
|
|
|
{ |
24
|
8 |
|
public static function getDriverClass($name) |
25
|
|
|
{ |
26
|
8 |
|
$namespace = 'Doyo\\Behat\\Coverage\\Bridge\\Driver\\'; |
27
|
8 |
|
if (version_compare(static::getVersion(), '6.0', '<')) { |
28
|
|
|
$namespace = $namespace.'Compat\\'; |
29
|
|
|
} |
30
|
8 |
|
$class = $namespace.$name; |
31
|
|
|
|
32
|
8 |
|
return $class; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function createDriver($name) |
36
|
|
|
{ |
37
|
|
|
$class = static::getDriverClass($name); |
38
|
|
|
|
39
|
|
|
return new $class(); |
40
|
|
|
} |
41
|
|
|
|
42
|
8 |
|
public static function getVersion() |
43
|
|
|
{ |
44
|
8 |
|
static $version; |
45
|
8 |
|
if (null === $version) { |
46
|
1 |
|
$version = Version::id(); |
47
|
|
|
} |
48
|
|
|
|
49
|
8 |
|
return $version; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function getCoverageValidConfigs() |
53
|
|
|
{ |
54
|
|
|
$r = new \ReflectionClass(CodeCoverage::class); |
55
|
|
|
$configs = []; |
56
|
|
|
$ignored = [ |
57
|
|
|
'data', |
58
|
|
|
'tests', |
59
|
|
|
'cachetokens', |
60
|
|
|
'maptestclassnametocoveredclassname', |
61
|
|
|
]; |
62
|
|
|
foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
63
|
|
|
$methodName = $method->getName(); |
64
|
|
|
if (false === strpos($methodName, 'set')) { |
65
|
|
|
continue; |
66
|
|
|
} |
67
|
|
|
$configName = substr($methodName, 3); |
68
|
|
|
$lower = strtolower($configName); |
69
|
|
|
if (\in_array($lower, $ignored, true)) { |
70
|
|
|
continue; |
71
|
|
|
} |
72
|
|
|
$defaults = $r->getDefaultProperties(); |
73
|
|
|
$configName = lcfirst($configName); |
74
|
|
|
$configs[$configName] = $defaults[$configName]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $configs; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|