Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: DOMElement::setAttribute(): string is not in UTF-8 #491

Open
Nayjest opened this issue Dec 12, 2016 · 7 comments
Open

Error: DOMElement::setAttribute(): string is not in UTF-8 #491

Nayjest opened this issue Dec 12, 2016 · 7 comments
Assignees

Comments

@Nayjest
Copy link

Nayjest commented Dec 12, 2016

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>
@theseer
Copy link
Contributor

theseer commented Apr 7, 2017

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?

@Nayjest
Copy link
Author

Nayjest commented Apr 9, 2017

Hi!

  1. Sorry, can't provide file, I even don't remember what project was related to this issue

  2. Yes, Windows 7 x64, php 5.6.*

@traab
Copy link

traab commented May 3, 2017

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

@theseer
Copy link
Contributor

theseer commented May 7, 2017

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?

@sebastianbergmann
Copy link
Owner

@theseer I have no problem with requiring iconv and/or mbstring if that is what it takes to properly solve this issue.

@stale stale bot added the stale label Apr 18, 2018
@stale stale bot closed this as completed Apr 25, 2018
@pelletiermaxime
Copy link

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

@theseer
Copy link
Contributor

theseer commented Jan 12, 2023

@sebastianbergmann Can we reopen this issue? I'll try to come up with a fix next week.

Repository owner deleted a comment from stale bot Jan 16, 2023
Repository owner deleted a comment from stale bot Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants