Skip to content

Commit

Permalink
Merge pull request #748 from ncharalampidis/2.x
Browse files Browse the repository at this point in the history
Fix parallel execution of test class that extends another class with same name
  • Loading branch information
nunomaduro committed Mar 29, 2023
2 parents 56ec3b9 + ca69e4f commit 152b7a9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/worker.php
Expand Up @@ -92,7 +92,7 @@
exit;
}

$exitCode = $application->runTest(trim($testPath));
$exitCode = $application->runTest(realpath(trim($testPath)));

fwrite($statusFile, (string) $exitCode);
fflush($statusFile);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -41,6 +41,7 @@
"autoload-dev": {
"psr-4": {
"Tests\\Fixtures\\Covers\\": "tests/Fixtures/Covers",
"Tests\\Fixtures\\Inheritance\\": "tests/Fixtures/Inheritance",
"Tests\\": "tests/PHPUnit/"
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Expand Up @@ -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>
Expand Down
8 changes: 7 additions & 1 deletion tests/.snapshots/allows-to-run-a-directory.txt
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion tests/.snapshots/success.txt
Expand Up @@ -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
Expand All @@ -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)
13 changes: 13 additions & 0 deletions tests/Fixtures/Inheritance/Base/ExampleTest.php
@@ -0,0 +1,13 @@
<?php

namespace Tests\Fixtures\Inheritance\Base;

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
public function testExample()
{
$this->markTestSkipped();
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Inheritance/ExampleTest.php
@@ -0,0 +1,11 @@
<?php

namespace Tests\Fixtures\Inheritance;

class ExampleTest extends Base\ExampleTest
{
public function testExample()
{
$this->assertTrue(true);
}
}
11 changes: 9 additions & 2 deletions tests/Visual/Parallel.php
Expand Up @@ -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'],
);

Expand All @@ -15,6 +17,11 @@
};

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('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 1 passed (1 assertions)');
});

0 comments on commit 152b7a9

Please sign in to comment.