mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge pull request #308 from titouanmathis/fix/test-key-separator
Fix/test key separator
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,6 +122,10 @@
|
|||||||
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
|
PASS Tests\PHPUnit\CustomAffixes\AdditionalFileExtensionspec
|
||||||
✓ it runs file names like `AdditionalFileExtension.spec.php`
|
✓ 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
|
PASS Tests\PHPUnit\CustomAffixes\ManyExtensionsclasstest
|
||||||
✓ it runs file names like `ManyExtensions.class.test.php`
|
✓ it runs file names like `ManyExtensions.class.test.php`
|
||||||
|
|
||||||
@ -220,5 +224,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 7 skipped, 120 passed
|
Tests: 7 skipped, 122 passed
|
||||||
|
|
||||||
19
tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php
Normal file
19
tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php
Normal 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();
|
||||||
Reference in New Issue
Block a user