diff --git a/src/Runners/PHPUnit/BaseRunner.php b/src/Runners/PHPUnit/BaseRunner.php index ccf06bc8..fc2f8bb9 100644 --- a/src/Runners/PHPUnit/BaseRunner.php +++ b/src/Runners/PHPUnit/BaseRunner.php @@ -135,10 +135,9 @@ final protected function log(): void return; } - $path = $this->options->path(); - assert($path !== null); + $name = $this->options->path() ?? ''; - $writer = new Writer($this->interpreter, $path); + $writer = new Writer($this->interpreter, $name); $writer->write($logJunit); } diff --git a/test/Unit/Runners/PHPUnit/BaseRunnerTest.php b/test/Unit/Runners/PHPUnit/BaseRunnerTest.php index c99f1a6c..f24bb097 100644 --- a/test/Unit/Runners/PHPUnit/BaseRunnerTest.php +++ b/test/Unit/Runners/PHPUnit/BaseRunnerTest.php @@ -104,10 +104,10 @@ public function testLogJUnitCreatesXmlFile(): void $this->assertJunitXmlIsCorrect($outputPath); } - public function assertJunitXmlIsCorrect(string $path): void + private function assertJunitXmlIsCorrect(string $path): void { $doc = simplexml_load_file($path); - assert($doc !== false); + static::assertNotFalse($doc); $suites = $doc->xpath('//testsuite'); $cases = $doc->xpath('//testcase'); $failures = $doc->xpath('//failure'); @@ -130,4 +130,27 @@ public function assertJunitXmlIsCorrect(string $path): void static::assertNotFalse($errors); static::assertCount(2, $errors); } + + public function testWritesLogWithEmptyNameWhenPathIsNotProvided(): void + { + $outputPath = TMP_DIR . DS . 'test-output.xml'; + + $this->bareOptions = [ + '--configuration' => $this->fixture('phpunit-passing.xml'), + '--log-junit' => $outputPath, + ]; + + $this->runRunner(); + + static::assertFileExists($outputPath); + $doc = simplexml_load_file($outputPath); + static::assertNotFalse($doc); + $suites = (array) $doc->children(); + static::assertArrayHasKey('testsuite', $suites); + $attribues = (array) $suites['testsuite']->attributes(); + static::assertArrayHasKey('@attributes', $attribues); + static::assertIsArray($attribues['@attributes']); + static::assertArrayHasKey('name', $attribues['@attributes']); + static::assertSame('', $attribues['@attributes']['name']); + } }