Move dependency mapping to TestCase

The `TestCaseFactory::getClassName` was removed since it can have
unexpected results when called too early, as it builds up the test class
prematurely. It is not currently used anywhere else.
This commit is contained in:
avrahamappel
2020-12-17 23:24:11 -05:00
parent f75a3ee865
commit b6e2763731
3 changed files with 20 additions and 20 deletions

View File

@ -7,6 +7,7 @@ namespace Pest\Concerns;
use Closure;
use Pest\Support\ExceptionTrace;
use Pest\TestSuite;
use PHPUnit\Framework\ExecutionOrderDependency;
use PHPUnit\Util\Test;
use Throwable;
@ -54,6 +55,24 @@ trait TestCase
$this->setGroups($groups);
}
/**
* Add dependencies to the test case and map them to instances of ExecutionOrderDependency.
*/
public function addDependencies(array $tests): void
{
$className = get_class($this);
$tests = array_map(function (string $test) use ($className): ExecutionOrderDependency {
if (strpos($test, '::') === false) {
$test = "{$className}::{$test}";
}
return new ExecutionOrderDependency($test, null, '');
}, $tests);
$this->setDependencies($tests);
}
/**
* Returns the test case name. Note that, in Pest
* we ignore withDataset argument as the description