This repository was archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperidot.coverage.php
109 lines (80 loc) · 2.72 KB
/
peridot.coverage.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
use cloak\CoverageAnalyzer;
use cloak\configuration\ConfigurationLoader;
use Evenement\EventEmitterInterface;
use Peridot\Configuration;
use Peridot\Console\Command;
use Peridot\Runner\SuiteLoaderInterface;
use expect\peridot\ExpectPlugin;
use Symfony\Component\Yaml\Yaml;
use Peridot\Reporter\Dot\DotReporterPlugin;
use holyshared\peridot\temporary\TemporaryPlugin;
class SuiteLoader implements SuiteLoaderInterface
{
public function load($path)
{
$tests = $this->getTests($path);
foreach ($tests as $test) {
include $test;
}
}
public function getTests($path)
{
$targetFiles = [];
$pattern = $this->excludesPattern();
$files = $this->getFileIterator();
foreach ($files as $key => $file) {
$pathName = $file->getPathname();
if (preg_match("/{$pattern}/", $pathName) === 1) {
continue;
}
if (preg_match("/.+spec\.php$/", $pathName) === 0) {
continue;
}
$targetFiles[] = $file;
}
return $targetFiles;
}
private function excludesPattern()
{
$coverageConfig = Yaml::parse(file_get_contents(__DIR__ . '/coverage.yml'));
$excludeTargets = $coverageConfig['targets'];
$quotePatterns = array_map(function($excludeTarget) {
return preg_quote($excludeTarget, DIRECTORY_SEPARATOR);
}, $excludeTargets);
$pattern = '(' . implode('|', $quotePatterns) . ')';
return $pattern;
}
private function getFileIterator()
{
$directoryIterator = new RecursiveDirectoryIterator(__DIR__ . '/spec',
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::SKIP_DOTS
);
$filterIterator = new RecursiveIteratorIterator(
$directoryIterator,
RecursiveIteratorIterator::LEAVES_ONLY
);
return $filterIterator;
}
}
return function(EventEmitterInterface $emitter)
{
ExpectPlugin::create()->registerTo($emitter);
TemporaryPlugin::create()->registerTo($emitter);
(new DotReporterPlugin($emitter));
$emitter->on('peridot.load', function(Command $command, Configuration $configuration) {
$command->setLoader(new SuiteLoader());
});
$analyzer = null;
$emitter->on('peridot.start', function() use(&$analyzer) {
$loader = new ConfigurationLoader();
$configuration = $loader->loadConfiguration('cloak.toml');
$analyzer = new CoverageAnalyzer($configuration);
$analyzer->start();
});
$emitter->on('peridot.end', function() use(&$analyzer) {
$analyzer->stop();
});
};