fix parallel execution of test class that inherit other class with the same name

This commit is contained in:
Nikos Charalampidis
2023-03-29 13:02:18 +03:00
parent ba87e1fde8
commit 1965763cd0
9 changed files with 59 additions and 5 deletions

View File

@ -92,7 +92,7 @@ $bootPest = (static function (): void {
exit;
}
$exitCode = $application->runTest(trim($testPath));
$exitCode = $application->runTest(realpath(trim($testPath)));
fwrite($statusFile, (string) $exitCode);
fflush($statusFile);

View File

@ -41,6 +41,7 @@
"autoload-dev": {
"psr-4": {
"Tests\\Fixtures\\Covers\\": "tests/Fixtures/Covers",
"Tests\\Fixtures\\Inheritance\\": "tests/Fixtures/Inheritance",
"Tests\\": "tests/PHPUnit/"
},
"files": [

View File

@ -18,6 +18,7 @@
<directory suffix=".php">./tests</directory>
<exclude>./tests/.snapshots</exclude>
<exclude>./tests/.tests</exclude>
<exclude>./tests/Fixtures/Inheritance</exclude>
</testsuite>
</testsuites>
<coverage>

View File

@ -8,4 +8,10 @@
PASS Tests\Fixtures\ExampleTest
✓ it example 2
Tests: 2 skipped, 2 passed (2 assertions)
WARN Tests\Fixtures\Inheritance\Base\ExampleTest
- example
PASS Tests\Fixtures\Inheritance\ExampleTest
✓ example
Tests: 3 skipped, 3 passed (3 assertions)

View File

@ -988,6 +988,7 @@
PASS Tests\Visual\Parallel
✓ parallel
✓ a parallel test can extend another test with same name
PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
@ -1008,4 +1009,4 @@
PASS Tests\Visual\Version
✓ visual snapshot of help command output
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 705 passed (1706 assertions)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 706 passed (1707 assertions)

View File

@ -0,0 +1,13 @@
<?php
namespace Tests\Fixtures\Inheritance\Base;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function testExample()
{
$this->markTestSkipped();
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace Tests\Fixtures\Inheritance;
class ExampleTest extends Base\ExampleTest
{
public function testExample()
{
$this->assertTrue(true);
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="../../vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Parallel Inheritance">
<directory suffix="Test.php">./Inheritance</directory>
<exclude>./Inheritance/Base</exclude>
</testsuite>
</testsuites>
</phpunit>

View File

@ -3,7 +3,9 @@
use Symfony\Component\Process\Process;
$run = function () {
$process = new Process(['php', 'bin/pest', '--parallel', '--processes=3', '--exclude-group=integration'], dirname(__DIR__, 2),
$process = new Process(
array_merge(['php', 'bin/pest', '--parallel', '--processes=3'], func_get_args()),
dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
);
@ -15,6 +17,12 @@ $run = function () {
};
test('parallel', function () use ($run) {
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 694 passed (1692 assertions)')
expect($run('--exclude-group=integration'))
->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 694 passed (1692 assertions)')
->toContain('Parallel: 3 processes');
})->skip(PHP_OS_FAMILY === 'Windows');
test('a parallel test can extend another test with same name', function () use ($run) {
expect($run('--configuration=tests/Fixtures/phpunit-parallel-inheritance.xml'))
->toContain('1 passed');
});