feat(tia): continues to work on poc

This commit is contained in:
nuno maduro
2026-04-16 07:15:44 -07:00
parent 247d59abf6
commit 50601e6118
5 changed files with 29 additions and 22 deletions

View File

@ -713,6 +713,6 @@ final class Tia implements AddsOutput, AfterEachable, BeforeEachable, HandlesArg
return false;
}
return property_exists($coverage, 'coverage') && $coverage->coverage === true;
return $coverage->coverage === true;
}
}

View File

@ -19,7 +19,7 @@ final readonly class Fingerprint
private const int SCHEMA_VERSION = 2;
/**
* @param non-empty-string $projectRoot
* @return array<string, int|string|null>
*/
public static function compute(string $projectRoot): array
{

View File

@ -166,11 +166,17 @@ final class Graph
return array_keys($this->edges);
}
/**
* @param array<string, int|string|null> $fingerprint
*/
public function setFingerprint(array $fingerprint): void
{
$this->fingerprint = $fingerprint;
}
/**
* @return array<string, int|string|null>
*/
public function fingerprint(): array
{
return $this->fingerprint;

View File

@ -69,12 +69,20 @@ final class Recorder
$this->driver = 'pcov';
$this->driverAvailable = true;
} elseif (function_exists('xdebug_start_code_coverage')) {
// Probe: Xdebug silently emits a warning and refuses to start
// when not in coverage mode. Suppress + check for mode errors.
$ok = @\xdebug_start_code_coverage();
// Xdebug is loaded. Probe whether coverage mode is active by
// attempting a start — it emits E_WARNING when the mode is off.
// We capture the warning via a temporary error handler.
$probeOk = true;
set_error_handler(static function () use (&$probeOk): bool {
$probeOk = false;
if ($ok === null || $ok) {
@\xdebug_stop_code_coverage(false);
return true;
});
\xdebug_start_code_coverage();
restore_error_handler();
if ($probeOk) {
\xdebug_stop_code_coverage(false);
$this->driver = 'xdebug';
$this->driverAvailable = true;
}
@ -195,31 +203,23 @@ final class Recorder
return null;
}
try {
$reflection = new ReflectionClass($className);
} catch (ReflectionException) {
return null;
}
$reflection = new ReflectionClass($className);
if ($reflection->hasProperty('__filename')) {
try {
$property = $reflection->getProperty('__filename');
$property = $reflection->getProperty('__filename');
if ($property->isStatic()) {
$value = $property->getValue();
if ($property->isStatic()) {
$value = $property->getValue();
if (is_string($value) && $value !== '') {
return $value;
}
if (is_string($value)) {
return $value;
}
} catch (ReflectionException) {
// fall through to getFileName()
}
}
$file = $reflection->getFileName();
return $file !== false && $file !== '' ? $file : null;
return is_string($file) ? $file : null;
}
/**

View File

@ -66,6 +66,7 @@ final class State
* Turns on replay mode with the given graph + affected set.
*
* @param array<string, true> $affectedFiles
* @param array<string, true> $previousDefects
*/
public function activate(string $projectRoot, Graph $graph, array $affectedFiles, array $previousDefects): void
{