-
Notifications
You must be signed in to change notification settings - Fork 27
/
peridot.php
87 lines (73 loc) · 3.26 KB
/
peridot.php
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
<?php
use Evenement\EventEmitterInterface;
use Peridot\Console\Environment;
use Peridot\Reporter\ReporterInterface;
use Symfony\Component\Console\Input\InputOption;
return function(EventEmitterInterface $emitter) {
$counts = ['pass' => 0, 'fail' => 0, 'pending' => 0];
$emitter->on('test.failed', function() use (&$counts) {
$counts['fail']++;
});
$emitter->on('test.passed', function() use (&$counts) {
$counts['pass']++;
});
$emitter->on('test.pending', function() use (&$counts) {
$counts['pending']++;
});
$codeCoverage = getenv('CODE_COVERAGE');
$hhvm = defined('HHVM_VERSION'); //exclude coverage from hhvm because its pretty flawed at the moment
$shouldCover = !$hhvm;
if ($codeCoverage == 'html' && $shouldCover) {
$coverage = new PHP_CodeCoverage();
$emitter->on('runner.start', function() use ($coverage) {
$coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/src');
$coverage->filter()->removeFileFromWhitelist(__DIR__ . '/src/Dsl.php');
$coverage->start('peridot');
});
$emitter->on('runner.end', function() use ($coverage) {
$coverage->stop();
$writer = new PHP_CodeCoverage_Report_HTML();
$writer->process($coverage, __DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'report');
});
}
if ($codeCoverage == 'clover' && $shouldCover) {
$coverage = new PHP_CodeCoverage();
$emitter->on('runner.start', function() use ($coverage) {
$coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/src');
$coverage->filter()->removeFileFromWhitelist(__DIR__ . '/src/Dsl.php');
$coverage->start('peridot');
});
$emitter->on('runner.end', function() use ($coverage) {
$coverage->stop();
$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process(
$coverage, __DIR__ . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR
. 'logs' . DIRECTORY_SEPARATOR . 'clover.xml');
});
}
$emitter->on('peridot.start', function(Environment $env) use (&$coverage) {
$definition = $env->getDefinition();
$definition->option("banner", null, InputOption::VALUE_REQUIRED, "Custom banner text");
$definition->getArgument('path')->setDefault('specs');
});
/**
* Demonstrate registering a custom reporter via peridot config
*/
$emitter->on('peridot.reporters', function($input, $reporters) use (&$counts) {
$banner = $input->getOption('banner');
$reporters->register('basic', 'a simple summary', function(ReporterInterface $reporter) use (&$counts, $banner) {
$output = $reporter->getOutput();
$reporter->getEventEmitter()->on('runner.start', function() use ($banner, $output) {
$output->writeln($banner);
});
$reporter->getEventEmitter()->on('runner.end', function() use ($output, &$counts) {
$output->writeln(sprintf(
'%d run, %d failed, %d pending',
$counts['pass'],
$counts['fail'],
$counts['pending']
));
});
});
});
};