Fix a bug where plugins could not be used in a path containing an @

Fix #307
This commit is contained in:
Titouan Mathis
2021-06-02 18:35:55 +02:00
parent 91eff755fd
commit c04d6d946d

View File

@ -19,6 +19,11 @@ use PHPUnit\Framework\TestCase;
*/ */
final class TestRepository final class TestRepository
{ {
/**
* @var string
*/
private const SEPARATOR = '>>>';
/** /**
* @var array<string, TestCaseFactory> * @var array<string, TestCaseFactory>
*/ */
@ -50,7 +55,7 @@ final class TestRepository
[$classOrTraits, $groups, $hooks] = $uses; [$classOrTraits, $groups, $hooks] = $uses;
$setClassName = function (TestCaseFactory $testCase, string $key) use ($path, $classOrTraits, $groups, $startsWith, $hooks): void { $setClassName = function (TestCaseFactory $testCase, string $key) use ($path, $classOrTraits, $groups, $startsWith, $hooks): void {
[$filename] = explode('@', $key); [$filename] = explode(self::SEPARATOR, $key);
if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) { if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) {
foreach ($classOrTraits as $class) { /** @var string $class */ foreach ($classOrTraits as $class) { /** @var string $class */
@ -131,10 +136,10 @@ final class TestRepository
throw ShouldNotHappen::fromMessage('Trying to create a test without description.'); throw ShouldNotHappen::fromMessage('Trying to create a test without description.');
} }
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) { if (array_key_exists(sprintf('%s%s%s', $test->filename, self::SEPARATOR, $test->description), $this->state)) {
throw new TestAlreadyExist($test->filename, $test->description); throw new TestAlreadyExist($test->filename, $test->description);
} }
$this->state[sprintf('%s@%s', $test->filename, $test->description)] = $test; $this->state[sprintf('%s%s%s', $test->filename, self::SEPARATOR, $test->description)] = $test;
} }
} }