JenkinsでxUnit pluginを使う場合、PHPUnitでjunit形式のログを出力しますが、あるときから、以下のようなエラーが大量に出力され、解析に失敗するようになりました。
type.3.2.2: 要素'testsuite'に属性'assertions'を含めることはできません。
WARNING: At line 2161 of file:/var/lib/jenkins/workspace/hoge/reports/phpunit.xml:cvc-complex-type.3.2.2: 要素'testsuite'に属性'warnings'を含めることはできません。
WARNING: At line 2161 of file:/var/lib/jenkins/workspace/hoge/reports/phpunit.xml:cvc-pattern-valid: 値'2.395662'は、タイプ'SUREFIRE_TIME'のパターン'(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?'に対してファセットが有効ではありません。
いろいろと調べたんですが、これという解決法が見つからなかったため、xUnit pluginが文句を言わないよう、出力されたログファイルを変換することで対処しました。
$project_root/tools/convert_phpunit_log.php
<?php
$buf = file_get_contents(__DIR__ . '/../reports/phpunit.xml');
$doc = new DOMDocument();
$doc->loadXML($buf);
$doc->formatOutput = true;
$nodes = $doc->getElementsByTagName('testcase');
foreach ($nodes as $node) {
$node->removeAttribute('class');
$node->removeAttribute('file');
$node->removeAttribute('line');
$node->removeAttribute('assertions');
$time = round($node->getAttribute('time'), 3);
$node->setAttribute('time', $time);
}
$nodes = $doc->getElementsByTagName('testsuite');
foreach ($nodes as $node) {
$node->removeAttribute('assertions');
$node->removeAttribute('warnings');
$node->removeAttribute('file');
$time = round($node->getAttribute('time'), 3);
$node->setAttribute('time', $time);
}
file_put_contents(__DIR__ . '/../reports/phpunit.xml', $doc->saveXML());
入出力のパスは適切なものに変更してください。
これをphpunit終了後に実行してください。