upgraded dependencies
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the php-code-coverage package.
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
@@ -9,17 +9,25 @@
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use function sprintf;
|
||||
use SebastianBergmann\CodeCoverage\BranchAndPathCoverageNotSupportedException;
|
||||
use SebastianBergmann\CodeCoverage\DeadCodeDetectionNotSupportedException;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverAvailableException;
|
||||
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
|
||||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
|
||||
|
||||
/**
|
||||
* Interface for code coverage drivers.
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
||||
*/
|
||||
interface Driver
|
||||
abstract class Driver
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @see http://xdebug.org/docs/code_coverage
|
||||
*/
|
||||
public const LINE_EXECUTED = 1;
|
||||
public const LINE_NOT_EXECUTABLE = -2;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
@@ -33,15 +41,127 @@ interface Driver
|
||||
*
|
||||
* @see http://xdebug.org/docs/code_coverage
|
||||
*/
|
||||
public const LINE_NOT_EXECUTABLE = -2;
|
||||
public const LINE_EXECUTED = 1;
|
||||
|
||||
/**
|
||||
* Start collection of code coverage information.
|
||||
* @var int
|
||||
*
|
||||
* @see http://xdebug.org/docs/code_coverage
|
||||
*/
|
||||
public function start(bool $determineUnusedAndDead = true): void;
|
||||
public const BRANCH_NOT_HIT = 0;
|
||||
|
||||
/**
|
||||
* Stop collection of code coverage information.
|
||||
* @var int
|
||||
*
|
||||
* @see http://xdebug.org/docs/code_coverage
|
||||
*/
|
||||
public function stop(): array;
|
||||
public const BRANCH_HIT = 1;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $collectBranchAndPathCoverage = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $detectDeadCode = false;
|
||||
|
||||
/**
|
||||
* @throws NoCodeCoverageDriverAvailableException
|
||||
* @throws PcovNotAvailableException
|
||||
* @throws PhpdbgNotAvailableException
|
||||
* @throws Xdebug2NotEnabledException
|
||||
* @throws Xdebug3NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*
|
||||
* @deprecated Use DriverSelector::forLineCoverage() instead
|
||||
*/
|
||||
public static function forLineCoverage(Filter $filter): self
|
||||
{
|
||||
return (new Selector)->forLineCoverage($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoCodeCoverageDriverWithPathCoverageSupportAvailableException
|
||||
* @throws Xdebug2NotEnabledException
|
||||
* @throws Xdebug3NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*
|
||||
* @deprecated Use DriverSelector::forLineAndPathCoverage() instead
|
||||
*/
|
||||
public static function forLineAndPathCoverage(Filter $filter): self
|
||||
{
|
||||
return (new Selector)->forLineAndPathCoverage($filter);
|
||||
}
|
||||
|
||||
public function canCollectBranchAndPathCoverage(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function collectsBranchAndPathCoverage(): bool
|
||||
{
|
||||
return $this->collectBranchAndPathCoverage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BranchAndPathCoverageNotSupportedException
|
||||
*/
|
||||
public function enableBranchAndPathCoverage(): void
|
||||
{
|
||||
if (!$this->canCollectBranchAndPathCoverage()) {
|
||||
throw new BranchAndPathCoverageNotSupportedException(
|
||||
sprintf(
|
||||
'%s does not support branch and path coverage',
|
||||
$this->nameAndVersion()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->collectBranchAndPathCoverage = true;
|
||||
}
|
||||
|
||||
public function disableBranchAndPathCoverage(): void
|
||||
{
|
||||
$this->collectBranchAndPathCoverage = false;
|
||||
}
|
||||
|
||||
public function canDetectDeadCode(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function detectsDeadCode(): bool
|
||||
{
|
||||
return $this->detectDeadCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DeadCodeDetectionNotSupportedException
|
||||
*/
|
||||
public function enableDeadCodeDetection(): void
|
||||
{
|
||||
if (!$this->canDetectDeadCode()) {
|
||||
throw new DeadCodeDetectionNotSupportedException(
|
||||
sprintf(
|
||||
'%s does not support dead code detection',
|
||||
$this->nameAndVersion()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->detectDeadCode = true;
|
||||
}
|
||||
|
||||
public function disableDeadCodeDetection(): void
|
||||
{
|
||||
$this->detectDeadCode = false;
|
||||
}
|
||||
|
||||
abstract public function nameAndVersion(): string;
|
||||
|
||||
abstract public function start(): void;
|
||||
|
||||
abstract public function stop(): RawCodeCoverageData;
|
||||
}
|
||||
|
@@ -1,45 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the php-code-coverage package.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
/**
|
||||
* Driver for PCOV code coverage functionality.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
final class PCOV implements Driver
|
||||
{
|
||||
/**
|
||||
* Start collection of code coverage information.
|
||||
*/
|
||||
public function start(bool $determineUnusedAndDead = true): void
|
||||
{
|
||||
\pcov\start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop collection of code coverage information.
|
||||
*/
|
||||
public function stop(): array
|
||||
{
|
||||
\pcov\stop();
|
||||
|
||||
$waiting = \pcov\waiting();
|
||||
$collect = [];
|
||||
|
||||
if ($waiting) {
|
||||
$collect = \pcov\collect(\pcov\inclusive, $waiting);
|
||||
|
||||
\pcov\clear();
|
||||
}
|
||||
|
||||
return $collect;
|
||||
}
|
||||
}
|
75
vendor/phpunit/php-code-coverage/src/Driver/PcovDriver.php
vendored
Normal file
75
vendor/phpunit/php-code-coverage/src/Driver/PcovDriver.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use const pcov\inclusive;
|
||||
use function array_intersect;
|
||||
use function extension_loaded;
|
||||
use function pcov\clear;
|
||||
use function pcov\collect;
|
||||
use function pcov\start;
|
||||
use function pcov\stop;
|
||||
use function pcov\waiting;
|
||||
use function phpversion;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
|
||||
|
||||
/**
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
||||
*/
|
||||
final class PcovDriver extends Driver
|
||||
{
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
/**
|
||||
* @throws PcovNotAvailableException
|
||||
*/
|
||||
public function __construct(Filter $filter)
|
||||
{
|
||||
if (!extension_loaded('pcov')) {
|
||||
throw new PcovNotAvailableException;
|
||||
}
|
||||
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function start(): void
|
||||
{
|
||||
start();
|
||||
}
|
||||
|
||||
public function stop(): RawCodeCoverageData
|
||||
{
|
||||
stop();
|
||||
|
||||
$filesToCollectCoverageFor = waiting();
|
||||
$collected = [];
|
||||
|
||||
if ($filesToCollectCoverageFor) {
|
||||
if (!$this->filter->isEmpty()) {
|
||||
$filesToCollectCoverageFor = array_intersect($filesToCollectCoverageFor, $this->filter->files());
|
||||
}
|
||||
|
||||
$collected = collect(inclusive, $filesToCollectCoverageFor);
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($collected);
|
||||
}
|
||||
|
||||
public function nameAndVersion(): string
|
||||
{
|
||||
return 'PCOV ' . phpversion('pcov');
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the php-code-coverage package.
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
@@ -9,54 +9,47 @@
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use SebastianBergmann\CodeCoverage\RuntimeException;
|
||||
use const PHP_SAPI;
|
||||
use const PHP_VERSION;
|
||||
use function array_diff;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function get_included_files;
|
||||
use function phpdbg_end_oplog;
|
||||
use function phpdbg_get_executable;
|
||||
use function phpdbg_start_oplog;
|
||||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
|
||||
|
||||
/**
|
||||
* Driver for PHPDBG's code coverage functionality.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
||||
*/
|
||||
final class PHPDBG implements Driver
|
||||
final class PhpdbgDriver extends Driver
|
||||
{
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws PhpdbgNotAvailableException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (\PHP_SAPI !== 'phpdbg') {
|
||||
throw new RuntimeException(
|
||||
'This driver requires the PHPDBG SAPI'
|
||||
);
|
||||
}
|
||||
|
||||
if (!\function_exists('phpdbg_start_oplog')) {
|
||||
throw new RuntimeException(
|
||||
'This build of PHPDBG does not support code coverage'
|
||||
);
|
||||
if (PHP_SAPI !== 'phpdbg') {
|
||||
throw new PhpdbgNotAvailableException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start collection of code coverage information.
|
||||
*/
|
||||
public function start(bool $determineUnusedAndDead = true): void
|
||||
public function start(): void
|
||||
{
|
||||
\phpdbg_start_oplog();
|
||||
phpdbg_start_oplog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop collection of code coverage information.
|
||||
*/
|
||||
public function stop(): array
|
||||
public function stop(): RawCodeCoverageData
|
||||
{
|
||||
static $fetchedLines = [];
|
||||
|
||||
$dbgData = \phpdbg_end_oplog();
|
||||
$dbgData = phpdbg_end_oplog();
|
||||
|
||||
if ($fetchedLines == []) {
|
||||
$sourceLines = \phpdbg_get_executable();
|
||||
if ($fetchedLines === []) {
|
||||
$sourceLines = phpdbg_get_executable();
|
||||
} else {
|
||||
$newFiles = \array_diff(\get_included_files(), \array_keys($fetchedLines));
|
||||
$newFiles = array_diff(get_included_files(), array_keys($fetchedLines));
|
||||
|
||||
$sourceLines = [];
|
||||
|
||||
@@ -71,14 +64,18 @@ final class PHPDBG implements Driver
|
||||
}
|
||||
}
|
||||
|
||||
$fetchedLines = \array_merge($fetchedLines, $sourceLines);
|
||||
$fetchedLines = array_merge($fetchedLines, $sourceLines);
|
||||
|
||||
return $this->detectExecutedLines($fetchedLines, $dbgData);
|
||||
return RawCodeCoverageData::fromXdebugWithoutPathCoverage(
|
||||
$this->detectExecutedLines($fetchedLines, $dbgData)
|
||||
);
|
||||
}
|
||||
|
||||
public function nameAndVersion(): string
|
||||
{
|
||||
return 'PHPDBG ' . PHP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert phpdbg based data into the format CodeCoverage expects
|
||||
*/
|
||||
private function detectExecutedLines(array $sourceLines, array $dbgData): array
|
||||
{
|
||||
foreach ($dbgData as $file => $coveredLines) {
|
79
vendor/phpunit/php-code-coverage/src/Driver/Selector.php
vendored
Normal file
79
vendor/phpunit/php-code-coverage/src/Driver/Selector.php
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use function phpversion;
|
||||
use function version_compare;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverAvailableException;
|
||||
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
|
||||
use SebastianBergmann\Environment\Runtime;
|
||||
|
||||
final class Selector
|
||||
{
|
||||
/**
|
||||
* @throws NoCodeCoverageDriverAvailableException
|
||||
* @throws PcovNotAvailableException
|
||||
* @throws PhpdbgNotAvailableException
|
||||
* @throws Xdebug2NotEnabledException
|
||||
* @throws Xdebug3NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*/
|
||||
public function forLineCoverage(Filter $filter): Driver
|
||||
{
|
||||
$runtime = new Runtime;
|
||||
|
||||
if ($runtime->hasPHPDBGCodeCoverage()) {
|
||||
return new PhpdbgDriver;
|
||||
}
|
||||
|
||||
if ($runtime->hasPCOV()) {
|
||||
return new PcovDriver($filter);
|
||||
}
|
||||
|
||||
if ($runtime->hasXdebug()) {
|
||||
if (version_compare(phpversion('xdebug'), '3', '>=')) {
|
||||
$driver = new Xdebug3Driver($filter);
|
||||
} else {
|
||||
$driver = new Xdebug2Driver($filter);
|
||||
}
|
||||
|
||||
$driver->enableDeadCodeDetection();
|
||||
|
||||
return $driver;
|
||||
}
|
||||
|
||||
throw new NoCodeCoverageDriverAvailableException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoCodeCoverageDriverWithPathCoverageSupportAvailableException
|
||||
* @throws Xdebug2NotEnabledException
|
||||
* @throws Xdebug3NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*/
|
||||
public function forLineAndPathCoverage(Filter $filter): Driver
|
||||
{
|
||||
if ((new Runtime)->hasXdebug()) {
|
||||
if (version_compare(phpversion('xdebug'), '3', '>=')) {
|
||||
$driver = new Xdebug3Driver($filter);
|
||||
} else {
|
||||
$driver = new Xdebug2Driver($filter);
|
||||
}
|
||||
|
||||
$driver->enableDeadCodeDetection();
|
||||
$driver->enableBranchAndPathCoverage();
|
||||
|
||||
return $driver;
|
||||
}
|
||||
|
||||
throw new NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
|
||||
}
|
||||
}
|
@@ -1,123 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the php-code-coverage package.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\RuntimeException;
|
||||
|
||||
/**
|
||||
* Driver for Xdebug's code coverage functionality.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
final class Xdebug implements Driver
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $cacheNumLines = [];
|
||||
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(Filter $filter = null)
|
||||
{
|
||||
if (!\extension_loaded('xdebug')) {
|
||||
throw new RuntimeException('This driver requires Xdebug');
|
||||
}
|
||||
|
||||
if (\version_compare(\phpversion('xdebug'), '3', '>=')) {
|
||||
$mode = \getenv('XDEBUG_MODE');
|
||||
|
||||
if ($mode === false) {
|
||||
$mode = \ini_get('xdebug.mode');
|
||||
}
|
||||
|
||||
if ($mode === false ||
|
||||
!\in_array('coverage', \explode(',', $mode), true)) {
|
||||
throw new RuntimeException('XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set');
|
||||
}
|
||||
} elseif (!\ini_get('xdebug.coverage_enable')) {
|
||||
throw new RuntimeException('xdebug.coverage_enable=On has to be set');
|
||||
}
|
||||
|
||||
if ($filter === null) {
|
||||
$filter = new Filter;
|
||||
}
|
||||
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start collection of code coverage information.
|
||||
*/
|
||||
public function start(bool $determineUnusedAndDead = true): void
|
||||
{
|
||||
if ($determineUnusedAndDead) {
|
||||
\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
||||
} else {
|
||||
\xdebug_start_code_coverage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop collection of code coverage information.
|
||||
*/
|
||||
public function stop(): array
|
||||
{
|
||||
$data = \xdebug_get_code_coverage();
|
||||
|
||||
\xdebug_stop_code_coverage();
|
||||
|
||||
return $this->cleanup($data);
|
||||
}
|
||||
|
||||
private function cleanup(array $data): array
|
||||
{
|
||||
foreach (\array_keys($data) as $file) {
|
||||
unset($data[$file][0]);
|
||||
|
||||
if (!$this->filter->isFile($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$numLines = $this->getNumberOfLinesInFile($file);
|
||||
|
||||
foreach (\array_keys($data[$file]) as $line) {
|
||||
if ($line > $numLines) {
|
||||
unset($data[$file][$line]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getNumberOfLinesInFile(string $fileName): int
|
||||
{
|
||||
if (!isset($this->cacheNumLines[$fileName])) {
|
||||
$buffer = \file_get_contents($fileName);
|
||||
$lines = \substr_count($buffer, "\n");
|
||||
|
||||
if (\substr($buffer, -1) !== "\n") {
|
||||
$lines++;
|
||||
}
|
||||
|
||||
$this->cacheNumLines[$fileName] = $lines;
|
||||
}
|
||||
|
||||
return $this->cacheNumLines[$fileName];
|
||||
}
|
||||
}
|
128
vendor/phpunit/php-code-coverage/src/Driver/Xdebug2Driver.php
vendored
Normal file
128
vendor/phpunit/php-code-coverage/src/Driver/Xdebug2Driver.php
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use const XDEBUG_CC_BRANCH_CHECK;
|
||||
use const XDEBUG_CC_DEAD_CODE;
|
||||
use const XDEBUG_CC_UNUSED;
|
||||
use const XDEBUG_FILTER_CODE_COVERAGE;
|
||||
use const XDEBUG_PATH_INCLUDE;
|
||||
use const XDEBUG_PATH_WHITELIST;
|
||||
use function defined;
|
||||
use function extension_loaded;
|
||||
use function ini_get;
|
||||
use function phpversion;
|
||||
use function sprintf;
|
||||
use function version_compare;
|
||||
use function xdebug_get_code_coverage;
|
||||
use function xdebug_set_filter;
|
||||
use function xdebug_start_code_coverage;
|
||||
use function xdebug_stop_code_coverage;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
|
||||
|
||||
/**
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
||||
*/
|
||||
final class Xdebug2Driver extends Driver
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $pathCoverageIsMixedCoverage;
|
||||
|
||||
/**
|
||||
* @throws WrongXdebugVersionException
|
||||
* @throws Xdebug2NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*/
|
||||
public function __construct(Filter $filter)
|
||||
{
|
||||
if (!extension_loaded('xdebug')) {
|
||||
throw new XdebugNotAvailableException;
|
||||
}
|
||||
|
||||
if (version_compare(phpversion('xdebug'), '3', '>=')) {
|
||||
throw new WrongXdebugVersionException(
|
||||
sprintf(
|
||||
'This driver requires Xdebug 2 but version %s is loaded',
|
||||
phpversion('xdebug')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!ini_get('xdebug.coverage_enable')) {
|
||||
throw new Xdebug2NotEnabledException;
|
||||
}
|
||||
|
||||
if (!$filter->isEmpty()) {
|
||||
if (defined('XDEBUG_PATH_WHITELIST')) {
|
||||
$listType = XDEBUG_PATH_WHITELIST;
|
||||
} else {
|
||||
$listType = XDEBUG_PATH_INCLUDE;
|
||||
}
|
||||
|
||||
xdebug_set_filter(
|
||||
XDEBUG_FILTER_CODE_COVERAGE,
|
||||
$listType,
|
||||
$filter->files()
|
||||
);
|
||||
}
|
||||
|
||||
$this->pathCoverageIsMixedCoverage = version_compare(phpversion('xdebug'), '2.9.6', '<');
|
||||
}
|
||||
|
||||
public function canCollectBranchAndPathCoverage(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canDetectDeadCode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function start(): void
|
||||
{
|
||||
$flags = XDEBUG_CC_UNUSED;
|
||||
|
||||
if ($this->detectsDeadCode() || $this->collectsBranchAndPathCoverage()) {
|
||||
$flags |= XDEBUG_CC_DEAD_CODE;
|
||||
}
|
||||
|
||||
if ($this->collectsBranchAndPathCoverage()) {
|
||||
$flags |= XDEBUG_CC_BRANCH_CHECK;
|
||||
}
|
||||
|
||||
xdebug_start_code_coverage($flags);
|
||||
}
|
||||
|
||||
public function stop(): RawCodeCoverageData
|
||||
{
|
||||
$data = xdebug_get_code_coverage();
|
||||
|
||||
xdebug_stop_code_coverage();
|
||||
|
||||
if ($this->collectsBranchAndPathCoverage()) {
|
||||
if ($this->pathCoverageIsMixedCoverage) {
|
||||
return RawCodeCoverageData::fromXdebugWithMixedCoverage($data);
|
||||
}
|
||||
|
||||
return RawCodeCoverageData::fromXdebugWithPathCoverage($data);
|
||||
}
|
||||
|
||||
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($data);
|
||||
}
|
||||
|
||||
public function nameAndVersion(): string
|
||||
{
|
||||
return 'Xdebug ' . phpversion('xdebug');
|
||||
}
|
||||
}
|
119
vendor/phpunit/php-code-coverage/src/Driver/Xdebug3Driver.php
vendored
Normal file
119
vendor/phpunit/php-code-coverage/src/Driver/Xdebug3Driver.php
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-code-coverage.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\CodeCoverage\Driver;
|
||||
|
||||
use const XDEBUG_CC_BRANCH_CHECK;
|
||||
use const XDEBUG_CC_DEAD_CODE;
|
||||
use const XDEBUG_CC_UNUSED;
|
||||
use const XDEBUG_FILTER_CODE_COVERAGE;
|
||||
use const XDEBUG_PATH_INCLUDE;
|
||||
use function explode;
|
||||
use function extension_loaded;
|
||||
use function getenv;
|
||||
use function in_array;
|
||||
use function ini_get;
|
||||
use function phpversion;
|
||||
use function sprintf;
|
||||
use function version_compare;
|
||||
use function xdebug_get_code_coverage;
|
||||
use function xdebug_set_filter;
|
||||
use function xdebug_start_code_coverage;
|
||||
use function xdebug_stop_code_coverage;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
|
||||
|
||||
/**
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
||||
*/
|
||||
final class Xdebug3Driver extends Driver
|
||||
{
|
||||
/**
|
||||
* @throws WrongXdebugVersionException
|
||||
* @throws Xdebug3NotEnabledException
|
||||
* @throws XdebugNotAvailableException
|
||||
*/
|
||||
public function __construct(Filter $filter)
|
||||
{
|
||||
if (!extension_loaded('xdebug')) {
|
||||
throw new XdebugNotAvailableException;
|
||||
}
|
||||
|
||||
if (version_compare(phpversion('xdebug'), '3', '<')) {
|
||||
throw new WrongXdebugVersionException(
|
||||
sprintf(
|
||||
'This driver requires Xdebug 3 but version %s is loaded',
|
||||
phpversion('xdebug')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$mode = getenv('XDEBUG_MODE');
|
||||
|
||||
if ($mode === false || $mode === '') {
|
||||
$mode = ini_get('xdebug.mode');
|
||||
}
|
||||
|
||||
if ($mode === false ||
|
||||
!in_array('coverage', explode(',', $mode), true)) {
|
||||
throw new Xdebug3NotEnabledException;
|
||||
}
|
||||
|
||||
if (!$filter->isEmpty()) {
|
||||
xdebug_set_filter(
|
||||
XDEBUG_FILTER_CODE_COVERAGE,
|
||||
XDEBUG_PATH_INCLUDE,
|
||||
$filter->files()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function canCollectBranchAndPathCoverage(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canDetectDeadCode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function start(): void
|
||||
{
|
||||
$flags = XDEBUG_CC_UNUSED;
|
||||
|
||||
if ($this->detectsDeadCode() || $this->collectsBranchAndPathCoverage()) {
|
||||
$flags |= XDEBUG_CC_DEAD_CODE;
|
||||
}
|
||||
|
||||
if ($this->collectsBranchAndPathCoverage()) {
|
||||
$flags |= XDEBUG_CC_BRANCH_CHECK;
|
||||
}
|
||||
|
||||
xdebug_start_code_coverage($flags);
|
||||
}
|
||||
|
||||
public function stop(): RawCodeCoverageData
|
||||
{
|
||||
$data = xdebug_get_code_coverage();
|
||||
|
||||
xdebug_stop_code_coverage();
|
||||
|
||||
if ($this->collectsBranchAndPathCoverage()) {
|
||||
return RawCodeCoverageData::fromXdebugWithPathCoverage($data);
|
||||
}
|
||||
|
||||
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($data);
|
||||
}
|
||||
|
||||
public function nameAndVersion(): string
|
||||
{
|
||||
return 'Xdebug ' . phpversion('xdebug');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user