Skip to content

Commit

Permalink
Fix LogMerger when no log is created (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
CanvasCompanyHylke authored Aug 6, 2024
1 parent 237a6ef commit 6f990d0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DOCKER_PHP_EXEC := docker compose run php
DOCKER_PHP_EXEC := docker compose run --rm php

SRCS := $(shell find ./src ./test -type f -not -path "*/tmp/*")

Expand Down Expand Up @@ -62,7 +62,7 @@ code-coverage: coverage/junit.xml
--ignore-msi-with-no-mutations \
--min-msi=100 \
$(INFECTION_ARGS)

.PHONY: clean
clean:
git clean -dfX
Expand Down
4 changes: 1 addition & 3 deletions src/JUnit/LogMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final class LogMerger
{
/** @param list<SplFileInfo> $junitFiles */
public function merge(array $junitFiles): TestSuite
public function merge(array $junitFiles): ?TestSuite
{
$mainSuite = null;
foreach ($junitFiles as $junitFile) {
Expand Down Expand Up @@ -67,8 +67,6 @@ public function merge(array $junitFiles): TestSuite
$mainSuite = $this->mergeSuites($mainSuite, $otherSuite);
}

assert($mainSuite !== null);

return $mainSuite;
}

Expand Down
4 changes: 4 additions & 0 deletions src/WrapperRunner/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ private function generateLogs(): void
}

$testSuite = (new LogMerger())->merge($this->junitFiles);
if ($testSuite === null) {
return;
}

(new Writer())->write(
$testSuite,
$this->options->configuration->logfileJunit(),
Expand Down
2 changes: 2 additions & 0 deletions test/Unit/JUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testMergeJunitLogs(): void

self::assertNotSame([], $junitFiles);
$testSuite = (new LogMerger())->merge($junitFiles);
self::assertNotNull($testSuite);

$outputFile = $tmpDir . '/result.xml';
(new Writer())->write(
Expand All @@ -63,6 +64,7 @@ public function testHandleSpecialChars(): void

$junitLog = FIXTURES . '/special_chars/data-provider-with-special-chars.xml';
$testSuite = (new LogMerger())->merge([new SplFileInfo($junitLog)]);
self::assertNotNull($testSuite);

$outputFile = $tmpDir . '/result.xml';
(new Writer())->write(
Expand Down
9 changes: 9 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ public function testTestdoxOutput(): void
);
}

public function testJunitOutputWithoutTests(): void
{
$this->bareOptions['path'] = $this->fixture('no_tests');
$this->bareOptions['--log-junit'] = $this->tmpDir . DIRECTORY_SEPARATOR . 'test-output.xml';
$runnerResult = $this->runRunner();

self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

public function testExitCodesPathWithoutTests(): void
{
$this->bareOptions['path'] = $this->fixture('no_tests');
Expand Down

0 comments on commit 6f990d0

Please sign in to comment.