2

I'm using: PHPUnit 3.6.12 / PHP 5.3.1 / MySQL 5.1.30

I'm trying to compare the value inserted by a function in a database with the value I expect.
The value is a string CONTAINING ACCENTS.

So I created a xml file: expectedValue.xml (file encoded in UTF-8)

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <table name="MyTable">
        <column>MyColumn</column>
        <row>
            <value>résumé</value>
        </row>
    </table>
</dataset>

Here is the code in the test method (file encoded in UTF-8 too)

public function testSave()
{
    // this function saves the data in an UTF-8 database
    save('résumé');     

    $queryTable = $this->getConnection()->createQueryTable('MyTable', 'SELECT MyColumn FROM MyTable') ;
    $expectedTable = $this->createXMLDataSet('expectedValue.xml)->getTable('MyTable') ;

    $this->assertTablesEqual($expectedTable, $queryTable) ;
}

And here is the result I get:

Failed asserting that

MYTable
MyColumn
résumé

is equal to expected
MyTable
MyColumn
résumé

Does anyone know where this encoding problem may come from ??
Thanks !!

1 Answer 1

2

Could possibly be the database connection

When you're connecting to MySQL (in your getConnection() method), you need to make sure you explicitly set UTF-8.

$pdo = new PDO( 
    'mysql:host=hostname;dbname=defaultDbName', 
    'username', 
    'password', 
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") 
); 

If you're not using MySQL, you can search for ways to set the charset.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.