yii2: FormatterNumberTest::testIntlAsScientific fails on GitLab

What steps will reproduce the problem?

See tests here: https://gitlab.com/yiisoft/yii2/-/jobs/368388365

What is the expected result?

No failure or error.

What do you get instead?

There was 1 failure:
573 1) yiiunit\framework\i18n\FormatterNumberTest::testIntlAsScientific
574 Failed asserting that two strings are identical.
575 --- Expected
576 +++ Actual
577 @@ @@
578 -8.76543210987654E16
579 +8.765432109876544E16
580 /project/tests/framework/i18n/FormatterNumberTest.php:531
581 /project/vendor/phpunit/phpunit/phpunit:52

Additional info

Q A
Yii version master
PHP version 7.1.33
Operating system Debian (Docker)

Looks like there’s one more digit now?! Test fails since https://gitlab.com/yiisoft/yii2/commit/c1e9739ed232e207ff6920e90b7351b2b19f69d0

Pipelines: https://gitlab.com/yiisoft/yii2/pipelines

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28 (28 by maintainers)

Commits related to this issue

Most upvoted comments

IMHO; either there should be a global default for precision, or the test should specify it. I believe the test should specify it, as it depends on the underlying system.

https://github.com/yiisoft/yii2/blob/master/tests/framework/i18n/FormatterNumberTest.php#L531

Overall conclusion is that the test is doing more harm than good. Going to mark it as always skipped.

@My6UoT9 want to do a pull request?

Yes will do a pr tomorrow morning, but I do not have the time to locally test it, I have the yii2 project not setup in that way. Might do that when I have more time available.

Seems to me like a bug in Yii. Php default is precision 14, but if intl is used - there is no default set. At least I cannot see any here: https://www.php.net/manual/en/class.numberformatter.php

Maybe would be good to set defaults.

The info at the function asScientific - its not prominent enough.

* If not given, the number of digits depends in the input value and is determined based on
     * `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION_DIGITS`, which can be configured
     * using [[$numberFormatterOptions]].
     * If the [PHP intl extension](https://secure.php.net/manual/en/book.intl.php) is not available, the default value depends on your PHP configuration.
     * If you want consistent behavior between environments where intl is available and not, you should explicitly
     * specify a value here.