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
<?php
namespace Codeception\Coverage\Subscriber;
use Codeception\Configuration;
use Codeception\Event\SuiteEvent;
use Codeception\Util\FileSystem;
/**
* When collecting code coverage on remote server
* data is retrieved over HTTP and not merged with the local code coverage results.
*
* Class RemoteServer
* @package Codeception\Coverage\Subscriber
*/
class RemoteServer extends LocalServer
{
public function isEnabled()
{
return $this->module and $this->settings['remote'] and $this->settings['enabled'];
}
public function afterSuite(SuiteEvent $e)
{
if (!$this->isEnabled()) {
return;
}
$suite = strtr($e->getSuite()->getName(), ['\\' => '.']);
if ($this->options['coverage-xml']) {
$this->retrieveAndPrintXml($suite);
}
if ($this->options['coverage-html']) {
$this->retrieveAndPrintHtml($suite);
}
if ($this->options['coverage-crap4j']) {
$this->retrieveAndPrintCrap4j($suite);
}
if ($this->options['coverage-phpunit']) {
$this->retrieveAndPrintPHPUnit($suite);
}
}
protected function retrieveAndPrintHtml($suite)
{
$tempFile = tempnam(sys_get_temp_dir(), 'C3') . '.tar';
file_put_contents($tempFile, $this->c3Request('html'));
$destDir = Configuration::outputDir() . $suite . '.remote.coverage';
if (is_dir($destDir)) {
FileSystem::doEmptyDir($destDir);
} else {
mkdir($destDir, 0777, true);
}
$phar = new \PharData($tempFile);
$phar->extractTo($destDir);
unlink($tempFile);
}
protected function retrieveAndPrintXml($suite)
{
$destFile = Configuration::outputDir() . $suite . '.remote.coverage.xml';
file_put_contents($destFile, $this->c3Request('clover'));
}
protected function retrieveAndPrintCrap4j($suite)
{
$destFile = Configuration::outputDir() . $suite . '.remote.crap4j.xml';
file_put_contents($destFile, $this->c3Request('crap4j'));
}
protected function retrieveAndPrintPHPUnit($suite)
{
$tempFile = tempnam(sys_get_temp_dir(), 'C3') . '.tar';
file_put_contents($tempFile, $this->c3Request('phpunit'));
$destDir = Configuration::outputDir() . $suite . '.remote.coverage-phpunit';
if (is_dir($destDir)) {
FileSystem::doEmptyDir($destDir);
} else {
mkdir($destDir, 0777, true);
}
$phar = new \PharData($tempFile);
$phar->extractTo($destDir);
unlink($tempFile);
}
}