|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the doyo/code-coverage project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Anthonius Munthi <https://itstoni.com> |
|
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\PhpSpec\CodeCoverage; |
|
15
|
|
|
|
|
16
|
|
|
use Doyo\Bridge\CodeCoverage\ContainerFactory; |
|
17
|
|
|
use Doyo\PhpSpec\CodeCoverage\Listener\CoverageListener; |
|
18
|
|
|
use PhpSpec\Extension as ExtensionInterface; |
|
19
|
|
|
use PhpSpec\ServiceContainer; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
22
|
|
|
|
|
23
|
|
|
class Extension implements ExtensionInterface |
|
24
|
|
|
{ |
|
25
|
1 |
|
public function load(ServiceContainer $container, array $params) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$this->addCoverageOptions($container); |
|
28
|
|
|
|
|
29
|
|
|
/** @var InputInterface $input */ |
|
30
|
1 |
|
$input = $container->get('console.input'); |
|
31
|
|
|
|
|
32
|
1 |
|
if (false === $input->hasParameterOption(['--coverage'], false)) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$container->define('doyo.coverage.container', function ($container) use ($params) { |
|
37
|
1 |
|
$coverageContainer = (new ContainerFactory($params))->getContainer(); |
|
38
|
1 |
|
$input = $container->get('console.input'); |
|
39
|
1 |
|
$output = $container->get('console.output'); |
|
40
|
1 |
|
$coverageContainer->set('console.input', $input); |
|
41
|
1 |
|
$coverageContainer->set('console.output', $output); |
|
42
|
|
|
|
|
43
|
1 |
|
return $coverageContainer; |
|
44
|
1 |
|
}); |
|
45
|
|
|
|
|
46
|
|
|
$container->define('doyo.coverage.listener', function ($container) { |
|
47
|
1 |
|
$coverageContainer = $container->get('doyo.coverage.container'); |
|
48
|
1 |
|
$coverage = $coverageContainer->get('coverage'); |
|
49
|
|
|
|
|
50
|
1 |
|
return new CoverageListener($coverage); |
|
51
|
1 |
|
}, ['event_dispatcher.listeners']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function addCoverageOptions(ServiceContainer $container) |
|
55
|
|
|
{ |
|
56
|
|
|
/** @var \PhpSpec\Console\Command\RunCommand $command */ |
|
57
|
1 |
|
$command = $container->get('console.commands.run'); |
|
58
|
1 |
|
$command->addOption( |
|
59
|
1 |
|
'coverage', |
|
60
|
1 |
|
null, |
|
61
|
1 |
|
InputOption::VALUE_NONE, |
|
62
|
1 |
|
'Run phpspec with code coverage' |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|