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
|
|
|
if (!isset($_SERVER[static::HEADER_SESSION_KEY])) { |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$name = $_SERVER[static::HEADER_SESSION_KEY]; |
33
|
|
|
$session = new static($name); |
34
|
|
|
if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) { |
35
|
|
|
$session->doStartSession(); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
return $session; |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
public function init(array $config) |
42
|
|
|
{ |
43
|
3 |
|
$filter = new Filter(); |
44
|
3 |
|
if (isset($config['filterOptions'])) { |
45
|
3 |
|
$filter->setWhitelistedFiles($config['filterOptions']['whitelistedFiles']); |
46
|
|
|
} |
47
|
|
|
|
48
|
3 |
|
$processor = new Processor(new Dummy(), $filter); |
49
|
3 |
|
$codeCoverage = $processor->getCodeCoverage(); |
50
|
3 |
|
if (isset($config['codeCoverageOptions'])) { |
51
|
3 |
|
foreach ($config['codeCoverageOptions'] as $method => $option) { |
52
|
2 |
|
$method = 'set'.ucfirst($method); |
53
|
2 |
|
\call_user_func_array([$codeCoverage, $method], [$option]); |
54
|
|
|
} |
55
|
3 |
|
$processor->setCodeCoverageOptions($config['codeCoverageOptions']); |
56
|
|
|
} |
57
|
3 |
|
$this->setProcessor($processor); |
58
|
3 |
|
$this->reset(); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
public function doStartSession() |
62
|
|
|
{ |
63
|
|
|
$name = $_SERVER[static::HEADER_TEST_CASE_KEY]; |
64
|
|
|
$testCase = new TestCase($name); |
65
|
|
|
$this->setTestCase($testCase); |
66
|
|
|
|
67
|
|
|
try{ |
68
|
|
|
$this->start(); |
69
|
1 |
|
register_shutdown_function([$this, 'shutdown']); |
70
|
|
|
}catch (\Exception $e){ |
71
|
|
|
$this->exceptions[] = $e->getMessage(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|