Skip to content

Commit

Permalink
BaseRunner -> Writer $name (#521)
Browse files Browse the repository at this point in the history
* BaseRunner -> Writer $name

* Update BaseRunner.php

* Update BaseRunner.php

* Update BaseRunner.php

* Update BaseRunner.php

* Add tests

Co-authored-by: Filippo Tessarotto <[email protected]>
  • Loading branch information
matthewnessworthy and Slamdunk authored Aug 26, 2020
1 parent 932e941 commit 17ef27a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/Runners/PHPUnit/BaseRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 25 additions & 2 deletions test/Unit/Runners/PHPUnit/BaseRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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']);
}
}

0 comments on commit 17ef27a

Please sign in to comment.