1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/code-coverage 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\Bridge\CodeCoverage\Session; |
15
|
|
|
|
16
|
|
|
use Doyo\Bridge\CodeCoverage\ContainerFactory; |
17
|
|
|
use Doyo\Bridge\CodeCoverage\Driver\Dummy; |
18
|
|
|
use Doyo\Bridge\CodeCoverage\Processor; |
19
|
|
|
use Doyo\Bridge\CodeCoverage\TestCase; |
20
|
|
|
use SebastianBergmann\CodeCoverage\Filter; |
21
|
|
|
|
22
|
|
|
class RemoteSession extends Session |
23
|
|
|
{ |
24
|
|
|
const HEADER_SESSION_KEY = 'HTTP_DOYO_COVERAGE_SESSION'; |
25
|
|
|
const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE'; |
26
|
|
|
|
27
|
|
|
public function __construct($name, array $config) |
28
|
|
|
{ |
29
|
|
|
parent::__construct($name); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function startSession() |
33
|
|
|
{ |
34
|
|
|
if (!isset($_SERVER[static::HEADER_SESSION_KEY])) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$name = $_SERVER[static::HEADER_SESSION_KEY]; |
39
|
|
|
$session = new static($name); |
|
|
|
|
40
|
|
|
if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) { |
41
|
|
|
$session->doStartSession(); |
42
|
|
|
} else { |
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
$session->save(); |
46
|
|
|
|
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function oldInit(array $config) |
51
|
|
|
{ |
52
|
|
|
$filter = new Filter(); |
53
|
|
|
if (isset($config['filterOptions'])) { |
54
|
|
|
$filter->setWhitelistedFiles($config['filterOptions']['whitelistedFiles']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$processor = new Processor(new Dummy(), $filter); |
58
|
|
|
$codeCoverage = $processor->getCodeCoverage(); |
59
|
|
|
if (isset($config['codeCoverageOptions'])) { |
60
|
|
|
foreach ($config['codeCoverageOptions'] as $method => $option) { |
61
|
|
|
$method = 'set'.ucfirst($method); |
62
|
|
|
\call_user_func_array([$codeCoverage, $method], [$option]); |
63
|
|
|
} |
64
|
|
|
$processor->setCodeCoverageOptions($config['codeCoverageOptions']); |
65
|
|
|
} |
66
|
|
|
$this->setProcessor($processor); |
67
|
|
|
$this->reset(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function init($name, array $config) |
71
|
|
|
{ |
72
|
|
|
$container = (new ContainerFactory($config))->getContainer(); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function doStartSession() |
76
|
|
|
{ |
77
|
|
|
$name = $_SERVER[static::HEADER_TEST_CASE_KEY]; |
78
|
|
|
$testCase = new TestCase($name); |
79
|
|
|
$this->setTestCase($testCase); |
80
|
|
|
|
81
|
|
|
try { |
82
|
|
|
$this->start(); |
83
|
|
|
register_shutdown_function([$this, 'shutdown']); |
84
|
|
|
} catch (\Exception $e) { |
85
|
|
|
$this->reset(); |
86
|
|
|
$this->exceptions[] = $e; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.