1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/behat-coverage-extension 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; |
15
|
|
|
|
16
|
|
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
17
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
18
|
|
|
use Doyo\Behat\Coverage\Compiler\CoveragePass; |
19
|
|
|
use Doyo\Behat\Coverage\Compiler\DriverPass; |
20
|
|
|
use Doyo\Behat\Coverage\Compiler\ReportPass; |
21
|
|
|
use SebastianBergmann\Environment\Runtime; |
22
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
23
|
|
|
use Symfony\Component\Config\FileLocator; |
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
25
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
26
|
|
|
|
27
|
|
|
class Extension implements ExtensionInterface |
28
|
|
|
{ |
29
|
1 |
|
public static function canCollectCodeCoverage() |
30
|
|
|
{ |
31
|
1 |
|
static $runtime; |
32
|
1 |
|
if(is_null($runtime)){ |
33
|
|
|
$runtime = new Runtime(); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
return $runtime->canCollectCodeCoverage(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function process(ContainerBuilder $container) |
40
|
|
|
{ |
41
|
|
|
} |
42
|
|
|
|
43
|
4 |
|
public function getConfigKey() |
44
|
|
|
{ |
45
|
4 |
|
return 'doyo'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function initialize(ExtensionManager $extensionManager) |
49
|
|
|
{ |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
public function configure(ArrayNodeDefinition $builder) |
53
|
|
|
{ |
54
|
4 |
|
$config = new Configuration(); |
55
|
4 |
|
$config->configure($builder); |
56
|
|
|
|
57
|
4 |
|
return $builder; |
58
|
|
|
} |
59
|
|
|
|
60
|
4 |
|
public function load(ContainerBuilder $container, array $config) |
61
|
|
|
{ |
62
|
4 |
|
$this->loadServices($container); |
63
|
|
|
|
64
|
4 |
|
$container->setParameter('doyo.coverage.options', $config['coverage']); |
65
|
4 |
|
$container->setParameter('doyo.coverage.config', $config); |
66
|
4 |
|
$container->setParameter('doyo.coverage.sessions', $config['sessions']); |
67
|
4 |
|
$container->setParameter('doyo.coverage.xdebug_patch', $config['xdebug_patch']); |
68
|
|
|
|
69
|
4 |
|
$reportFormats = ['clover', 'crap4j', 'html', 'php', 'text', 'xml']; |
70
|
4 |
|
foreach ($reportFormats as $format) { |
71
|
4 |
|
$name = 'doyo.coverage.report.'.$format; |
72
|
4 |
|
$container->setParameter($name, $config['report'][$format]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
4 |
|
private function loadServices(ContainerBuilder $container) |
77
|
|
|
{ |
78
|
4 |
|
$locator = new FileLocator(__DIR__.'/Resources/config'); |
79
|
4 |
|
$loader = new XmlFileLoader($container, $locator); |
80
|
|
|
|
81
|
4 |
|
$loader->load('core.xml'); |
82
|
4 |
|
$loader->load('drivers.xml'); |
83
|
4 |
|
$loader->load('coverage.xml'); |
84
|
4 |
|
$loader->load('report.xml'); |
85
|
|
|
|
86
|
4 |
|
$container->addCompilerPass(new DriverPass()); |
87
|
4 |
|
$container->addCompilerPass(new ReportPass()); |
88
|
4 |
|
$container->addCompilerPass(new CoveragePass()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|