I have the following phpunit assert:
$this->assertRegExp('/^\d.\d{3}$/i', $this->object->transformNumber('3333', 'de_AT'));
// $number = '3333' and $lang = 'de_AT'
and the relevant part of transformNumber
:
$formatter = new \NumberFormatter($lang, \NumberFormatter::DECIMAL);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 2);
return $formatter->format($number);
Here intl acts different I've learned that because of the different Intl Versions different outputs can result.
Now my question is why do I get this and the unit test fails:
Failed asserting that '3 333' matches PCRE pattern "/^\d.\d{3}$/i".
As it clear matches the result: regex 101
Info: Runtime: PHP 7.0.20 with Xdebug 2.5.4
EDIT:
After I rewrote the test to:
$result = $this->object->transformNumber('3333', 'de_AT');
printf($result);
echo "\n";
foreach (str_split($result) as $char) {
printf('char: %s => ord: %s', $char, ord($char));
echo "\n";
}
I got the follwoing output:
3 333
char: 3 => ord: 51
char: � => ord: 194
char: � => ord: 160
char: 3 => ord: 51
char: 3 => ord: 51
char: 3 => ord: 51
That means that on some machines with different setup (php version/ intl version and so on) I get an extra character (actually 2 Ascii chars instead of space) in the number. Is this an Intl problem?
And I've adjusted the regex to:
$this->assertRegExp('/^\d.(.)?\d{3}$/i', $result);
Now a new question is rising: Why do I get this encoding problem only on some environments?