mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
TestSuiteLoader will always consider classes from the current file
This commit is contained in:
@ -60,6 +60,11 @@ final class TestSuiteLoader
|
|||||||
*/
|
*/
|
||||||
private static array $loadedClasses = [];
|
private static array $loadedClasses = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @psalm-var array<string, array<class-string>>
|
||||||
|
*/
|
||||||
|
private static array $loadedClassesByFilename = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @psalm-var list<class-string>
|
* @psalm-var list<class-string>
|
||||||
*/
|
*/
|
||||||
@ -97,6 +102,17 @@ final class TestSuiteLoader
|
|||||||
|
|
||||||
self::$loadedClasses = array_merge($loadedClasses, self::$loadedClasses);
|
self::$loadedClasses = array_merge($loadedClasses, self::$loadedClasses);
|
||||||
|
|
||||||
|
foreach ($loadedClasses as $loadedClass) {
|
||||||
|
$reflection = new ReflectionClass($loadedClass);
|
||||||
|
$filename = $reflection->getFileName();
|
||||||
|
self::$loadedClassesByFilename[$filename] = [
|
||||||
|
$loadedClass,
|
||||||
|
...self::$loadedClassesByFilename[$filename] ?? [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$loadedClasses = array_merge(self::$loadedClassesByFilename[$suiteClassFile] ?? [], $loadedClasses);
|
||||||
|
|
||||||
if (empty($loadedClasses)) {
|
if (empty($loadedClasses)) {
|
||||||
return $this->exceptionFor($suiteClassName, $suiteClassFile);
|
return $this->exceptionFor($suiteClassName, $suiteClassFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1015,9 +1015,15 @@
|
|||||||
PASS Tests\PHPUnit\CustomAffixes\snakecasespec
|
PASS Tests\PHPUnit\CustomAffixes\snakecasespec
|
||||||
✓ it runs file names like snake_case_spec.php
|
✓ it runs file names like snake_case_spec.php
|
||||||
|
|
||||||
|
PASS Tests\CustomTestCase\ChildTest
|
||||||
|
✓ override method
|
||||||
|
|
||||||
PASS Tests\CustomTestCase\ExecutedTest
|
PASS Tests\CustomTestCase\ExecutedTest
|
||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
|
PASS Tests\CustomTestCase\ParentTest
|
||||||
|
✓ override method
|
||||||
|
|
||||||
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
|
||||||
✓ closure was bound to CustomTestCase
|
✓ closure was bound to CustomTestCase
|
||||||
|
|
||||||
@ -1210,4 +1216,4 @@
|
|||||||
WARN Tests\Visual\Version
|
WARN Tests\Visual\Version
|
||||||
- visual snapshot of help command output
|
- visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 860 passed (1975 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 862 passed (1977 assertions)
|
||||||
|
|||||||
@ -19,7 +19,13 @@
|
|||||||
↓ something todo later chained
|
↓ something todo later chained
|
||||||
↓ something todo later chained and with function body
|
↓ something todo later chained and with function body
|
||||||
|
|
||||||
|
PASS Tests\CustomTestCase\ChildTest
|
||||||
|
✓ override method
|
||||||
|
|
||||||
PASS Tests\CustomTestCase\ExecutedTest
|
PASS Tests\CustomTestCase\ExecutedTest
|
||||||
✓ that gets executed
|
✓ that gets executed
|
||||||
|
|
||||||
Tests: 13 todos, 1 passed (1 assertions)
|
PASS Tests\CustomTestCase\ParentTest
|
||||||
|
✓ override method
|
||||||
|
|
||||||
|
Tests: 13 todos, 3 passed (3 assertions)
|
||||||
|
|||||||
13
tests/PHPUnit/CustomTestCase/ChildTest.php
Normal file
13
tests/PHPUnit/CustomTestCase/ChildTest.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\CustomTestCase;
|
||||||
|
|
||||||
|
class ChildTest extends ParentTest
|
||||||
|
{
|
||||||
|
private function getEntity(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
tests/PHPUnit/CustomTestCase/ParentTest.php
Normal file
22
tests/PHPUnit/CustomTestCase/ParentTest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\CustomTestCase;
|
||||||
|
|
||||||
|
use function PHPUnit\Framework\assertTrue;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParentTest extends TestCase
|
||||||
|
{
|
||||||
|
private function getEntity(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function testOverrideMethod(): void
|
||||||
|
{
|
||||||
|
assertTrue($this->getEntity() || true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 849 passed (1960 assertions)')
|
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 851 passed (1962 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user