mirror of
https://github.com/pestphp/pest.git
synced 2026-12-05 07:15:33 +01:00
fix(tia): restrict Xdebug coverage to the source scope before tracing (#2091)
* fix(tia): restrict Xdebug coverage to the source scope before tracing * fix(tia): set the Xdebug exclude filter before the bootstrap and keep case twins traced --------- Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -4,9 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use PHPUnit\Event\Dispatcher;
|
||||
use PHPUnit\Event\DispatchingEmitter;
|
||||
use PHPUnit\Event\Emitter;
|
||||
use PHPUnit\Event\Event;
|
||||
use PHPUnit\Event\Facade as EventFacade;
|
||||
use PHPUnit\Event\Telemetry\System;
|
||||
use PHPUnit\Event\Telemetry\SystemCpuTimeMeter;
|
||||
use PHPUnit\Event\Telemetry\SystemGarbageCollectorStatusProvider;
|
||||
use PHPUnit\Event\Telemetry\SystemMemoryMeter;
|
||||
use PHPUnit\Event\Telemetry\SystemStopWatch;
|
||||
use PHPUnit\TextUI\CliArguments\Builder;
|
||||
use PHPUnit\TextUI\CliArguments\XmlConfigurationFileFinder;
|
||||
use PHPUnit\TextUI\XmlConfiguration\DefaultConfiguration;
|
||||
use PHPUnit\TextUI\XmlConfiguration\Loader;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -18,16 +29,18 @@ final readonly class ConfigurationFile
|
||||
|
||||
private const array DEFAULT_NAMES = ['phpunit.xml', 'phpunit.dist.xml', 'phpunit.xml.dist'];
|
||||
|
||||
private const array VALUE_OPTIONS = ['--configuration', '--bootstrap', '--include-path'];
|
||||
private const array VALUE_OPTIONS = ['--configuration', '--bootstrap', '--include-path', '--coverage-filter'];
|
||||
|
||||
/**
|
||||
* @param list<string>|null $includePaths
|
||||
* @param list<string> $coverageFilter
|
||||
*/
|
||||
private function __construct(
|
||||
private ?string $path,
|
||||
private bool $suppressed,
|
||||
private ?string $bootstrap = null,
|
||||
private ?array $includePaths = null,
|
||||
private array $coverageFilter = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -45,19 +58,20 @@ final readonly class ConfigurationFile
|
||||
$includePaths = $configuration->hasIncludePath()
|
||||
? array_map(self::resolved(...), explode(PATH_SEPARATOR, $configuration->includePath()))
|
||||
: null;
|
||||
$coverageFilter = $configuration->hasCoverageFilter() ? $configuration->coverageFilter() : [];
|
||||
|
||||
if (! $configuration->hasConfigurationFile() && ! $configuration->useDefaultConfiguration()) {
|
||||
return new self(null, true, $bootstrap, $includePaths);
|
||||
return new self(null, true, $bootstrap, $includePaths, $coverageFilter);
|
||||
}
|
||||
|
||||
$file = new XmlConfigurationFileFinder()->find($configuration);
|
||||
$path = $file === false ? false : realpath($file);
|
||||
|
||||
if ($path !== false && $generatedPath !== null && $path === realpath($generatedPath)) {
|
||||
return new self(null, false, $bootstrap, $includePaths);
|
||||
return new self(null, false, $bootstrap, $includePaths, $coverageFilter);
|
||||
}
|
||||
|
||||
return new self($path === false ? null : $path, false, $bootstrap, $includePaths);
|
||||
return new self($path === false ? null : $path, false, $bootstrap, $includePaths, $coverageFilter);
|
||||
}
|
||||
|
||||
public static function at(string $path): self
|
||||
@@ -70,6 +84,23 @@ final readonly class ConfigurationFile
|
||||
return new self(null, false);
|
||||
}
|
||||
|
||||
public function sourceScope(string $projectRoot): ?SourceScope
|
||||
{
|
||||
$path = $this->suppressed ? null : ($this->path ?? $this->defaultIn($projectRoot));
|
||||
|
||||
if ($path === null) {
|
||||
return SourceScope::fromSource($projectRoot, DefaultConfiguration::create()->source(), $this->coverageFilter);
|
||||
}
|
||||
|
||||
try {
|
||||
$source = new Loader($this->silentEmitter())->load($path)->source();
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return SourceScope::fromSource($projectRoot, $source, $this->coverageFilter);
|
||||
}
|
||||
|
||||
public function bootstrapFingerprint(string $projectRoot): ?string
|
||||
{
|
||||
return $this->bootstrap === null ? null : $this->relativeTo($projectRoot, $this->bootstrap);
|
||||
@@ -174,6 +205,22 @@ final readonly class ConfigurationFile
|
||||
return $argument;
|
||||
}
|
||||
|
||||
private function silentEmitter(): Emitter
|
||||
{
|
||||
return new DispatchingEmitter(
|
||||
new class implements Dispatcher
|
||||
{
|
||||
public function dispatch(Event $event): void {}
|
||||
},
|
||||
new System(
|
||||
new SystemStopWatch,
|
||||
new SystemMemoryMeter,
|
||||
new SystemGarbageCollectorStatusProvider,
|
||||
new SystemCpuTimeMeter,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private function withForwardSlashes(string $path): string
|
||||
{
|
||||
return DIRECTORY_SEPARATOR === '\\' ? str_replace('\\', '/', $path) : $path;
|
||||
|
||||
Reference in New Issue
Block a user