Skip to content

[PHPUnitBridge] Allow setting the locale using SYMFONY_PHPUNIT_LOCALE env var #19089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ The PHPUnit Bridge

It comes with the following features:

* Forces the tests to use a consistent locale (``C``) (if you create
locale-sensitive tests, use PHPUnit's ``setLocale()`` method);
* Sets by default a consistent locale (``C``) for your tests (if you
create locale-sensitive tests, use PHPUnit's ``setLocale()`` method);

* Auto-register ``class_exists`` to load Doctrine annotations (when used);

Expand Down Expand Up @@ -402,6 +402,41 @@ Log Deprecations
For turning the verbose output off and write it to a log file instead you can use
``SYMFONY_DEPRECATIONS_HELPER='logFile=/path/deprecations.log'``.

Setting The Locale For Tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, the PHPUnit Bridge forces the locale to ``C`` to avoid locale
issues in tests. This behavior can be changed by setting the
``SYMFONY_PHPUNIT_LOCALE`` environment variable to the desired locale:

.. code-block:: bash

# .env.test
SYMFONY_PHPUNIT_LOCALE="fr_FR"

Alternatively, you can set this environment variable in the PHPUnit
configuration file:

.. code-block:: xml

<!-- https://phpunit.de/manual/6.0/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
>

<!-- ... -->

<php>
<!-- ... -->
<env name="SYMFONY_PHPUNIT_LOCALE" value="fr_FR"/>
</php>
</phpunit>

.. versionadded:: 6.4

The support for the ``SYMFONY_PHPUNIT_LOCALE`` environment variable was
introduced in Symfony 6.4.

.. _write-assertions-about-deprecations:

Write Assertions about Deprecations
Expand Down