For some reason, when running mb_convert_encoding in phpunit, I am getting unexpected results. For example doing the following:
var_dump( mb_convert_encoding( utf8_decode( 'ö' ), 'UTF-8' ) === 'ö' )
The above returns bool (true) under PHP-FPM, and PHP-CLI, however under PHPunit returns false, mb_convert_encoding() is doing something, it just encodes to a messed up string.
My guess is you are using a different set of mbstring ini settings. Here is one way to troubleshoot that. First in the cli you can run
php -i |grep -i "mb"to see them.Then create a phpunit test that asserts the values are all the same. Here is mine (I only did the likely suspects):
Aside: I couldn’t get your code to work. I needed to tell it the source encoding is ISO-8859-1. I.e. auto-detection of input character set got it wrong. If you’re just looking for a quick fix and don’t care why, adding that 3rd parameter explicitly to
mb_convert_encodingmay be all you need.