Skip to content

Commit 1648aa7

Browse files
authored
Fix JUnit XML missing test cases when merging suites in --functional mode (#1097)
1 parent 2b45150 commit 1648aa7

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/JUnit/TestSuite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function mergeWith(self $other): self
125125
continue;
126126
}
127127

128-
$suites[$otherSuiteName]->mergeWith($otherSuite);
128+
$suites[$otherSuiteName] = $suites[$otherSuiteName]->mergeWith($otherSuite);
129129
}
130130

131131
ksort($suites);

test/Unit/JUnitTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@ public function testLoadTestSuiteContainingMultipleSuitesWithSameName(): void
8383
self::assertCount(2, $testSuite->suites['ParaTest\Tests\fixtures\github\GH997\SuccessfulTests']->cases);
8484
self::assertEquals(2, $testSuite->suites['ParaTest\Tests\fixtures\github\GH997\SuccessfulTests']->tests);
8585
}
86+
87+
public function testMergeSameSuiteAcrossWorkers(): void
88+
{
89+
$junitFiles = [
90+
new SplFileInfo(FIXTURES . '/functional_merge/worker1.xml'),
91+
new SplFileInfo(FIXTURES . '/functional_merge/worker2.xml'),
92+
];
93+
94+
$testSuite = (new LogMerger())->merge($junitFiles);
95+
self::assertNotNull($testSuite);
96+
97+
// 3 distinct class suites: ExampleTest (in both), OtherTest, AnotherTest
98+
self::assertCount(3, $testSuite->suites);
99+
self::assertArrayHasKey('App\Tests\ExampleTest', $testSuite->suites);
100+
self::assertArrayHasKey('App\Tests\OtherTest', $testSuite->suites);
101+
self::assertArrayHasKey('App\Tests\AnotherTest', $testSuite->suites);
102+
103+
// ExampleTest appeared in both workers — all 4 cases must be present
104+
$exampleSuite = $testSuite->suites['App\Tests\ExampleTest'];
105+
self::assertSame(4, $exampleSuite->tests);
106+
self::assertSame(4, $exampleSuite->assertions);
107+
self::assertCount(4, $exampleSuite->cases);
108+
self::assertSame('testOne', $exampleSuite->cases[0]->name);
109+
self::assertSame('testTwo', $exampleSuite->cases[1]->name);
110+
self::assertSame('testThree', $exampleSuite->cases[2]->name);
111+
self::assertSame('testFour', $exampleSuite->cases[3]->name);
112+
}
86113
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="App\Tests\ExampleTest" file="tests/ExampleTest.php" tests="2" assertions="2" errors="0" failures="0" skipped="0" time="0.100000">
4+
<testcase name="testOne" file="tests/ExampleTest.php" line="10" class="App\Tests\ExampleTest" classname="App.Tests.ExampleTest" assertions="1" time="0.050000"/>
5+
<testcase name="testTwo" file="tests/ExampleTest.php" line="15" class="App\Tests\ExampleTest" classname="App.Tests.ExampleTest" assertions="1" time="0.050000"/>
6+
</testsuite>
7+
<testsuite name="App\Tests\OtherTest" file="tests/OtherTest.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="0.050000">
8+
<testcase name="testAlpha" file="tests/OtherTest.php" line="10" class="App\Tests\OtherTest" classname="App.Tests.OtherTest" assertions="1" time="0.050000"/>
9+
</testsuite>
10+
</testsuites>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="App\Tests\ExampleTest" file="tests/ExampleTest.php" tests="2" assertions="2" errors="0" failures="0" skipped="0" time="0.200000">
4+
<testcase name="testThree" file="tests/ExampleTest.php" line="20" class="App\Tests\ExampleTest" classname="App.Tests.ExampleTest" assertions="1" time="0.100000"/>
5+
<testcase name="testFour" file="tests/ExampleTest.php" line="25" class="App\Tests\ExampleTest" classname="App.Tests.ExampleTest" assertions="1" time="0.100000"/>
6+
</testsuite>
7+
<testsuite name="App\Tests\AnotherTest" file="tests/AnotherTest.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="0.050000">
8+
<testcase name="testBeta" file="tests/AnotherTest.php" line="10" class="App\Tests\AnotherTest" classname="App.Tests.AnotherTest" assertions="1" time="0.050000"/>
9+
</testsuite>
10+
</testsuites>

0 commit comments

Comments
 (0)