Skip to content

Commit ff0c4e8

Browse files
committed
fix empty filename attributes on testsuite level
1 parent 6c918a9 commit ff0c4e8

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/PhpunitMerger/Command/LogCommand.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
4848
$this->document->formatOutput = true;
4949

5050
$root = $this->document->createElement('testsuites');
51+
$baseSuite = $this->document->createElement('testsuite');
52+
$baseSuite->setAttribute('name', "");
53+
$baseSuite->setAttribute('tests', "0");
54+
$baseSuite->setAttribute('assertions', "0");
55+
$baseSuite->setAttribute('errors', "0");
56+
$baseSuite->setAttribute('failures', "0");
57+
$baseSuite->setAttribute('skipped', "0");
58+
$baseSuite->setAttribute('time', "0");
59+
60+
$root->appendChild($baseSuite);
5161
$this->document->appendChild($root);
5262

5363
foreach ($finder as $file) {
5464
try {
5565
$xml = new \SimpleXMLElement(file_get_contents($file->getRealPath()));
5666
$xmlArray = json_decode(json_encode($xml), true);
5767
if (!empty($xmlArray)) {
58-
$this->addTestSuites($root, $xmlArray);
68+
$this->addTestSuites($baseSuite, $xmlArray);
5969
}
6070
} catch (\Exception $exception) {
6171
// Initial fallthrough
@@ -95,7 +105,6 @@ private function addTestSuites(\DOMElement $parent, array $testSuites)
95105
$element->setAttribute('parent', $parent->getAttribute('name'));
96106
$attributes = $testSuite['@attributes'] ?? [];
97107
foreach ($attributes as $key => $value) {
98-
$value = $key === 'name' ? $value : 0;
99108
$element->setAttribute($key, (string)$value);
100109
}
101110
$parent->appendChild($element);
@@ -142,13 +151,16 @@ private function addTestCases(\DOMElement $parent, array $testCases)
142151

143152
private function addAttributeValueToTestSuite(\DOMElement $element, $key, $value)
144153
{
145-
$currentValue = $element->hasAttribute($key) ? $element->getAttribute($key) : 0;
146-
$element->setAttribute($key, (string)($currentValue + $value));
147-
148-
if ($element->hasAttribute('parent')) {
149-
$parent = $element->getAttribute('parent');
150-
if (isset($this->domElements[$parent])) {
151-
$this->addAttributeValueToTestSuite($this->domElements[$parent], $key, $value);
154+
$keysToCalculate = ["assertions", "time", "tests", "errors", "failures", "skipped"];
155+
if (in_array($key, $keysToCalculate)) {
156+
$currentValue = $element->hasAttribute($key) ? $element->getAttribute($key) : 0;
157+
$element->setAttribute($key, (string)($currentValue + $value));
158+
159+
if ($element->hasAttribute('parent')) {
160+
$parent = $element->getAttribute('parent');
161+
if (isset($this->domElements[$parent])) {
162+
$this->addAttributeValueToTestSuite($this->domElements[$parent], $key, $value);
163+
}
152164
}
153165
}
154166
}

0 commit comments

Comments
 (0)