Error: DOMElement::setAttribute(): string is not in UTF-8
Generating code coverage report in Clover XML format ... Warning: DOMElement::setAttribute(): string is not in UTF-8 in ...\vendor\phpunit\php-code-coverage\src\Report\Clover.php on line 58
Versions:
"name": "phpunit/php-code-coverage",
"version": "4.0.x-dev",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "31fbb24b4a5e7070a1e626318fabfe0fa1c1a18e"
},
"name": "phpunit/phpunit",
"version": "5.7.x-dev",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "951435d443b6cb60006e61e9ef132224f2b42265"
},
phpunit.xml.dist:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="./build/phpunit/index.xml"/>
<log type="coverage-html" target="./build/phpunit/html"/>
</logging>
</phpunit>
As Line 58 is trying to set the file name attribute of the context node, the problem must reside within the path or name of the file currently being worked on. Can you provide the stripped down example with a the problematic file name so a fix can be considered?
Based on the backslashes within the error message, I presume this is on windows?
Hi!
-
Sorry, can't provide file, I even don't remember what project was related to this issue
-
Yes, Windows 7 x64, php 5.6.*
Hi,
I have a similar problem. My files are encoded in ISO-8859-1 (It's a legacy project). Generating code coverage results in
Warning: DOMElement::setAttribute(): string is not in UTF-8 in C:\Users\t.raab\AppData\Roaming\Composer\vendor\phpunit\php-code-coverage\src\Report\Clover.php on line 170
Changing line 170 in Clover.php to
$xmlLine->setAttribute('name', utf8_encode($data['name']));
solves the problem.
I am also forced to work on Windows 7 x64, php 5.6
There are likely various places where encoding issues might cause this error. As for now, the problem seems to have occured on line 58 and 170.
While using utf8_encode might have fixed it for @traab, this is not going to be a viable solution for the general code base. The function utf8_encode should be removed from PHP as it only works with input that is (still) in ISO-8859-1. Worst, it silently assumes it is ISO-8559-1 no matter what.
To fix this, we should probably incorporate a more sophisticated conversion. That would probably require iconv and/or mbstring to be present though.
@sebastianbergmann What do you think?
@theseer I have no problem with requiring iconv and/or mbstring if that is what it takes to properly solve this issue.
I am experiencing the same problem in a legacy project encoded in iso-8859-1. I'm using phpunit 9.5.20 and php-code-coverage 9.2.15 in linux. The exact error when I run:
bin/phpunit --log-junit report.xml --debug
Is:
Test 'Namespaces\Filename::testSOmething with data set "Uppercase - red�marrer" ('RED�MARRER')' started DOMElement::setAttribute(): string is not in UTF-8
@sebastianbergmann Can we reopen this issue? I'll try to come up with a fix next week.