Skip to content

Commit

Permalink
TestCase: list all possible TestCase class dependencies (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
milo committed Jan 3, 2021
1 parent c0b7ee0 commit 1c843cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Framework/TestCase.php
Expand Up @@ -36,9 +36,10 @@ public function run(): void
throw new \LogicException('Calling TestCase::run($method) is deprecated. Use TestCase::runTest($method) instead.');
}

$ro = new \ReflectionObject($this);
$methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm): string {
return $rm->getName();
}, (new \ReflectionObject($this))->getMethods())));
}, $ro->getMethods())));

if (isset($_SERVER['argv']) && ($tmp = preg_filter('#--method=([\w-]+)$#Ai', '$1', $_SERVER['argv']))) {
$method = reset($tmp);
Expand All @@ -48,6 +49,22 @@ public function run(): void
echo "\n";
echo 'TestCase:' . static::class . "\n";
echo 'Method:' . implode("\nMethod:", $methods) . "\n";

$dependentFiles = [];
$reflections = [$ro];
while (count($reflections)) {
$rc = array_shift($reflections);
$dependentFiles[$rc->getFileName()] = 1;

if ($rpc = $rc->getParentClass()) {
$reflections[] = $rpc;
}

foreach ($rc->getTraits() as $rt) {
$reflections[] = $rt;
}
}
echo 'Dependency:' . implode("\nDependency:", array_keys($dependentFiles)) . "\n";
return;
}
$this->runTest($method);
Expand Down

0 comments on commit 1c843cf

Please sign in to comment.