|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\ApplicationFactory; |
|
4
|
|
|
use PhpSpec\Console\Application; |
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class CodeCoverageGenerator |
|
13
|
|
|
*/ |
|
14
|
|
|
class CodeCoverageGenerator extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('code-coverage:generate') |
|
20
|
|
|
->setDescription('Generates a code coverage report'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Builds the code coverage clove report file |
|
25
|
|
|
* |
|
26
|
|
|
* @param InputInterface $input |
|
27
|
|
|
* @param OutputInterface $output |
|
28
|
|
|
* |
|
29
|
|
|
* @return int|null|void |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$filter = new PHP_CodeCoverage_Filter(); |
|
34
|
|
|
$filter->addDirectoryToBlacklist(realpath(__DIR__.'/../console')); |
|
35
|
|
|
$filter->addDirectoryToBlacklist(realpath(__DIR__.'/../features')); |
|
36
|
|
|
$filter->addDirectoryToBlacklist(realpath(__DIR__.'/../spec')); |
|
37
|
|
|
$filter->addDirectoryToBlacklist(realpath(__DIR__.'/../vendor')); |
|
38
|
|
|
|
|
39
|
|
|
$coverage = new PHP_CodeCoverage(null, $filter); |
|
40
|
|
|
|
|
41
|
|
|
$coverage->start('<tests>'); |
|
42
|
|
|
$input = new ArgvInput(['phpspec', 'run', '--format=pretty']); |
|
43
|
|
|
$app = new Application(null); |
|
44
|
|
|
$app->setAutoExit(false); |
|
45
|
|
|
$exit = $app->run($input, new ConsoleOutput()); |
|
46
|
|
|
if ($exit !== 0) { |
|
47
|
|
|
exit($exit); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
define('BEHAT_BIN_PATH', realpath(__DIR__.'/../bin/behat')); |
|
51
|
|
|
$input = new ArgvInput(['behat']); |
|
52
|
|
|
$factory = new ApplicationFactory(); |
|
53
|
|
|
$app = $factory->createApplication(); |
|
54
|
|
|
$app->setAutoExit(false); |
|
55
|
|
|
$exit = $app->run($input, new ConsoleOutput()); |
|
56
|
|
|
if ($exit !== 0) { |
|
57
|
|
|
exit($exit); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$coverage->stop(); |
|
61
|
|
|
|
|
62
|
|
|
$writer = new PHP_CodeCoverage_Report_Clover; |
|
63
|
|
|
$writer->process($coverage, realpath(__DIR__.'/..').'/clover.xml'); |
|
64
|
|
|
|
|
65
|
|
|
$writer = new PHP_CodeCoverage_Report_HTML(); |
|
66
|
|
|
$writer->process($coverage, realpath(__DIR__.'/..').'/code-coverage'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|