Merge pull request #308 from titouanmathis/fix/test-key-separator

Fix/test key separator
This commit is contained in:
Luke Downing
2021-06-07 15:22:05 +01:00
committed by GitHub
3 changed files with 32 additions and 4 deletions

View File

@ -19,6 +19,11 @@ use PHPUnit\Framework\TestCase;
*/
final class TestRepository
{
/**
* @var string
*/
private const SEPARATOR = '>>>';
/**
* @var array<string, TestCaseFactory>
*/
@ -50,7 +55,7 @@ final class TestRepository
[$classOrTraits, $groups, $hooks] = $uses;
$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))) {
foreach ($classOrTraits as $class) { /** @var string $class */
@ -131,10 +136,10 @@ final class TestRepository
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);
}
$this->state[sprintf('%s@%s', $test->filename, $test->description)] = $test;
$this->state[sprintf('%s%s%s', $test->filename, self::SEPARATOR, $test->description)] = $test;
}
}

View File

@ -122,6 +122,10 @@
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
✓ it runs file names like `AdditionalFileExtension.spec.php`
PASS Tests\PHPUnit\CustomAffixes\FolderWithAn\ExampleTest
✓ custom traits can be used
✓ trait applied in this file
PASS Tests\PHPUnit\CustomAffixes\ManyExtensionsclasstest
✓ it runs file names like `ManyExtensions.class.test.php`
@ -220,5 +224,5 @@
✓ it is a test
✓ it uses correct parent class
Tests: 7 skipped, 120 passed
Tests: 7 skipped, 122 passed

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
class MyCustomClassTest extends PHPUnit\Framework\TestCase
{
public function assertTrueIsTrue()
{
$this->assertTrue(true);
}
}
uses(MyCustomClassTest::class);
test('custom traits can be used', function () {
$this->assertTrueIsTrue();
});
test('trait applied in this file')->assertTrueIsTrue();