Review main Merged

48416[BUGFIX] Get current locale without changing environment

Christian Kuhn CR +2 V +2 Normal +51 −34 updated 05/31/16, 15:24

Commit message

Two tests in ext:form change the environment when they try to
back up the current locale:
setlocale(LC_NUMERIC, null): "the locale names will be set from
the values of environment variables", should be
setlocale(LC_NUMERIC, 0): "the locale setting is not affected,
only the current setting is returned"
In my case my default LC_NUMERIC is "C" and after call with 'null'
it is set to and returns 'de_DE.utf8', so it changes the internal
state to something else than before and the reset from backup does
not work properly. This leads to hard to debug problems if other
locale depending tests are executed later.
As a fun fact, phpunit suffers from the same issue and its
api method "setlocale()" that should take care of proper reset
messes this up, too. A pull request is pending to fix that.

The patch fixes the affected unit tests and cleans them up
along the way. Another patch to improve the overall situation
regarding locale handling in unit tests will follow later.

Review

  • Code review CR +2
    • Morton Jonuschat +2
    • Markus Klein +1
  • Verified V +2
    • Morton Jonuschat +2
    • Markus Klein +1

Issues 1

Files 2

Review log 10

  1. Christian Kuhn uploaded patch set 1 05/31/16, 10:43

  2. Christian Kuhn commented on patch set 1 05/31/16, 10:52

  3. Markus Klein commented on patch set 1 05/31/16, 10:56

    FloatValidatorTest.php:63

    these tests are subject to fail anyways, since on some servers this locale is called 'de_DE.UTF-8'
  4. Elmar Hinz commented on patch set 1 05/31/16, 10:58

    Isn't it a general issue, that some unit tests may need to set environment variables influencing other test when not properly set back? IMHO running test with the processIsolation option could solve this, but is is only set for functional tests. What do you think of a third type in between, unit tests, but called with process isolation?
  5. Mathias Brodala commented on patch set 1 05/31/16, 11:01

    > What do you think of a third type in between, unit tests, but > called with process isolation? Or simply run this test in isolation, it's only a single annotation to add.
  6. Elmar Hinz commented on patch set 1 05/31/16, 11:12

    Right. I was looking for such an annotation, too. I just comes by a different name: @runInSeparateProcess There is also an annotation to run all tests of the class in isolation: @runTestsInSeparateProcesses
  7. Christian Kuhn commented on patch set 1 05/31/16, 12:20

    no process isolation for unit tests, pleas. this would make the setup much slower, error handling is more complicated and xdebug doesn't work well. actually, the tests are encapsulated pretty well - most globals are backed up (except one where i'll add another patch soonish), and there is not that much global scope that annoys us apart from php built-in global scope like this locale stuff. other than that, there is mostly only singleton handling, and that is currently clean and an integrity test checks this is not messed up. So: keep current encapsulation and only fix the remaining details that are left.

    FloatValidatorTest.php:63 Reply

    yes, i'll try to tackle that with additional setup tests later. this one is to fix this annoying error.
  8. Markus Klein voted on patch set 1 CR +1 V +1 05/31/16, 13:45

  9. Morton Jonuschat voted on patch set 1 CR +2 V +2 05/31/16, 15:24

  10. Gerrit merged patch set 1 05/31/16, 15:24