Skip to content

[Validator] Class "Locale" not found #54833

@deasraze

Description

@deasraze

Symfony version(s) affected

7.0.7 or lower

Description

The symfony/validator package offers the ConstraintValidatorTestCase class to simplify testing of custom constraints. It includes a default locale override using the Locale class provided by the intl extension:
https://github.com/symfony/validator/blob/0edd0a59dfb8766d49cba51aa31af8287e05ccba/Test/ConstraintValidatorTestCase.php#L85-L86
And restores the locale back to its default state:
https://github.com/symfony/validator/blob/0edd0a59dfb8766d49cba51aa31af8287e05ccba/Test/ConstraintValidatorTestCase.php#L98
However, the symfony/validator package does not explicitly require the intl extension or the symfony/polyfill-intl-icu package. This leads to an error if the ConstraintValidatorTestCase class is used without the extension or polyfill being installed:

Error: Class "Locale" not found
/app/vendor/symfony/validator/Test/ConstraintValidatorTestCase.php:85

How to reproduce

Create a test class that extends ConstraintValidatorTestCase and includes the test method. In this scenario, ensure that neither the intl extension nor the polyfill package is installed.

Possible Solution

We won't need to override the Default locale if the \Locale class doesn't exist or we need adding warning/error, that say require an explicit dependency of Locale to improve DX.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions