1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/behat-coverage-extension project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
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\Behat\Coverage\Bridge\CodeCoverage\Session; |
15
|
|
|
|
16
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Driver\Dummy; |
17
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Processor; |
18
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\TestCase; |
19
|
|
|
use SebastianBergmann\CodeCoverage\Filter; |
20
|
|
|
|
21
|
|
|
class RemoteSession extends Session |
22
|
|
|
{ |
23
|
|
|
const HEADER_SESSION_KEY = 'HTTP_DOYO_COVERAGE_SESSION'; |
24
|
|
|
const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE'; |
25
|
|
|
|
26
|
1 |
|
public static function startSession() |
27
|
|
|
{ |
28
|
1 |
|
if (!isset($_SERVER[static::HEADER_SESSION_KEY])) { |
29
|
1 |
|
return false; |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
$name = $_SERVER[static::HEADER_SESSION_KEY]; |
33
|
1 |
|
$session = new static($name); |
34
|
1 |
|
if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) { |
35
|
1 |
|
$session->doStartSession(); |
36
|
|
|
}else{ |
37
|
1 |
|
return false; |
38
|
|
|
} |
39
|
1 |
|
$session->save(); |
40
|
|
|
|
41
|
1 |
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
7 |
|
public function init(array $config) |
45
|
|
|
{ |
46
|
7 |
|
$filter = new Filter(); |
47
|
7 |
|
if (isset($config['filterOptions'])) { |
48
|
7 |
|
$filter->setWhitelistedFiles($config['filterOptions']['whitelistedFiles']); |
49
|
|
|
} |
50
|
|
|
|
51
|
7 |
|
$processor = new Processor(new Dummy(), $filter); |
52
|
7 |
|
$codeCoverage = $processor->getCodeCoverage(); |
53
|
7 |
|
if (isset($config['codeCoverageOptions'])) { |
54
|
7 |
|
foreach ($config['codeCoverageOptions'] as $method => $option) { |
55
|
5 |
|
$method = 'set'.ucfirst($method); |
56
|
5 |
|
\call_user_func_array([$codeCoverage, $method], [$option]); |
57
|
|
|
} |
58
|
7 |
|
$processor->setCodeCoverageOptions($config['codeCoverageOptions']); |
59
|
|
|
} |
60
|
7 |
|
$this->setProcessor($processor); |
61
|
7 |
|
$this->reset(); |
62
|
5 |
|
} |
63
|
|
|
|
64
|
2 |
|
public function doStartSession() |
65
|
|
|
{ |
66
|
1 |
|
$name = $_SERVER[static::HEADER_TEST_CASE_KEY]; |
67
|
1 |
|
$testCase = new TestCase($name); |
68
|
1 |
|
$this->setTestCase($testCase); |
69
|
|
|
|
70
|
|
|
try{ |
71
|
1 |
|
$this->start(); |
72
|
2 |
|
register_shutdown_function([$this, 'shutdown']); |
73
|
1 |
|
}catch (\Exception $e){ |
74
|
1 |
|
$this->reset(); |
75
|
1 |
|
$this->exceptions[] = $e; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|