Skip to content

[Translation] Fix test, null is valid according to the tests #32386

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

Closed

Conversation

Simperfit
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR not needed.

The tests passes now.

@Simperfit Simperfit force-pushed the fix/fix-translation-tests branch from de7747b to ed56c53 Compare July 5, 2019 08:15
*
* @throws InvalidArgumentException If the locale contains invalid characters
*/
public function addResource(string $format, $resource, string $locale, string $domain = null)
public function addResource(string $format, $resource, ?string $locale, string $domain = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this could work. The assertValidLocale() call below will throw an exception when null is pass for the $locale argument, won't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we look at the test null is a valid locale, maybe the tests are wrong ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertValidLocale does not seems to throw on null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think we should deprecate the possibility to pass null here. Looking at how it is used it doesn't seem like it was intended to be supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addResource and similar methods changed here require a $locale argument which does not have a default null value and does not implement the fallback to the defaut locale like for example

if (null === $locale) {
$locale = $this->getLocale();
} else {
$this->assertValidLocale($locale);

for this reason, I agree that the $locale should not be nullable and calling $this->resources[$locale] with null is also strange. so I'm in favor of deprecating null in those places and not making it nullable.

Copy link
Contributor

@Tobion Tobion Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the locale is nullable in

public function __construct(?string $locale, array $messages = [])
but the getter is not nullable.
* @return string The locale
*/
public function getLocale();

It seems usages of getLocale would also not expect null. So the nullable in the MessageCatalogue constructor should also be deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to do it

@Simperfit
Copy link
Contributor Author

Closing in favor of #32415

@Simperfit Simperfit closed this Jul 7, 2019
@Simperfit Simperfit deleted the fix/fix-translation-tests branch July 7, 2019 07:04
fabpot added a commit that referenced this pull request Jul 8, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

[Translation] deprecate passing a null locale

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | none <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | not needed <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

According to the discussion in #32386 (comment) it seems that allowing null here was not the right thing to do, so we are deprecating this behaviour.

Commits
-------

088615d [Translation] deprecate passing a null locale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants