doyolabs /
behat-code-coverage
| 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\TestCase; |
||
| 17 | use phpDocumentor\Reflection\Types\Parent_; |
||
| 18 | use Symfony\Component\HttpFoundation\Request; |
||
| 19 | |||
| 20 | class RemoteSession extends Session |
||
| 21 | { |
||
| 22 | const HEADER_SESSION_KEY = 'HTTP_DOYO_COVERAGE_SESSION'; |
||
| 23 | const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE'; |
||
| 24 | |||
| 25 | 1 | public static function startSession(Request $request = null) |
|
|
0 ignored issues
–
show
|
|||
| 26 | { |
||
| 27 | if (!isset($_SERVER[static::HEADER_SESSION_KEY])) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | $name = $_SERVER[static::HEADER_SESSION_KEY]; |
||
| 32 | $session = new static($name); |
||
| 33 | if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) { |
||
| 34 | $name = $_SERVER[static::HEADER_TEST_CASE_KEY]; |
||
| 35 | $testCase = new TestCase($name); |
||
| 36 | $session->setTestCase($testCase); |
||
| 37 | |||
| 38 | $session->start(); |
||
| 39 | 1 | register_shutdown_function([$session,'shutdown']); |
|
| 40 | |||
| 41 | 1 | $session->xdebugPatch(); |
|
| 42 | } |
||
| 43 | |||
| 44 | 1 | return $session; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @codeCoverageIgnore |
||
| 49 | */ |
||
| 50 | public function xdebugPatch() |
||
| 51 | { |
||
| 52 | $options = $this->filterOptions; |
||
| 53 | $filterKey = 'whitelistedFiles'; |
||
| 54 | |||
| 55 | if( |
||
| 56 | !extension_loaded('xdebug') |
||
| 57 | || !function_exists('xdebug_set_filter') |
||
| 58 | || !isset($options[$filterKey]) |
||
| 59 | ){ |
||
| 60 | return; |
||
| 61 | } |
||
| 62 | |||
| 63 | $dirs = []; |
||
| 64 | foreach($options[$filterKey] as $fileName => $status){ |
||
| 65 | $dir = dirname($fileName); |
||
| 66 | if(!in_array($dir, $dirs)){ |
||
| 67 | $dirs[] = $dir; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | xdebug_set_filter( |
||
| 72 | XDEBUG_FILTER_CODE_COVERAGE, |
||
|
1 ignored issue
–
show
|
|||
| 73 | XDEBUG_PATH_WHITELIST, |
||
|
1 ignored issue
–
show
|
|||
| 74 | $dirs |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | 2 | public function init(array $config) |
|
| 79 | { |
||
| 80 | 2 | if (isset($config['codeCoverageOptions'])) { |
|
| 81 | 2 | $this->setCodeCoverageOptions($config['codeCoverageOptions']); |
|
| 82 | } |
||
| 83 | |||
| 84 | 2 | if (isset($config['filterOptions'])) { |
|
| 85 | 2 | $this->setFilterOptions($config['filterOptions']); |
|
| 86 | } |
||
| 87 | |||
| 88 | 2 | $this->reset(); |
|
| 89 | } |
||
| 90 | |||
| 91 | 1 | public function stop() |
|
| 92 | { |
||
| 93 | 1 | $processor = $this->processor; |
|
| 94 | 1 | $aggregate = $this->data; |
|
| 95 | |||
| 96 | 1 | $processor->stop(); |
|
| 97 | 1 | $processor->updateCoverage($aggregate); |
|
| 98 | |||
| 99 | 1 | $this->data = $processor->getData(); |
|
| 100 | } |
||
| 101 | } |
||
| 102 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.