-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translator]Test case refactoring and simplifications for the Translator class #14291
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
[Translator]Test case refactoring and simplifications for the Translator class #14291
Conversation
|
||
foreach (array(false, true) as $debug) { | ||
// Prime the cache | ||
$translator = new Translator($locale, null, $this->tmpDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing debug argument
new Translator($locale, null, $this->tmpDir, $debug)
the failed test for |
can you squash your commits into one, please |
Done. |
This would be easier with a true/false provider in my opinion: public function booleanProvider()
{
return array(array(true), array(false));
}
/**
* @dataProvider booleanProvider
*/
public function testSomething($debug)
{
} Then you would just test it with true and with false instead of implementing a foreach in each method. |
|
As the Thanks @iltar! |
@@ -466,11 +466,12 @@ private function getFallbackContent(MessageCatalogue $catalogue) | ||
private function getCatalogueCachePath($locale) | ||
{ | ||
$catalogueHash = sha1(serialize(array( | ||
'locale' => $this->locale, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about it , if someone wants to manually refresh the cache for en
catalogue for example ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple translations cache warmup (that is now available) should clear all cached translations for which the Resources have changed/expired, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but locale
is a catalog identifier and include it in catalogueHash makes difficult to identify catalog file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
@mpdude can you squash your commits :) |
Squashed. |
|
||
$this->assertEquals('foo A', $translator->trans('foo')); | ||
$catalogue = new MessageCatalogue($locale, array()); | ||
$catalogue->addResource(new StaleResource()); // better use a helper class than a mock, because it gets serialized in the cache and re-loaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use mock here the only thing that doesn't work as expected is expects
method.
$resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
$resource->method('isFresh')->will($this->returnValue(false));
catalogue->addResource($resource);
Hm, sounds a bit whacky, doesn't it? But if you prefer I'll change that. |
@mpdude ok keep it as you like it 😄 |
|
||
$this->assertEquals('foo B', $translator->trans('foo')); | ||
// 1st pass | ||
$translator = new Translator($locale, null, $this->tmpDir, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can simplify below code by:
$translator = new Translator($locale, null, $this->tmpDir, true);
$translator->addLoader($format, $loader);
$translator->addResource($format, null, $locale);
// 1st pass
$translator->trans($msgid);
// 2nd pass
$translator->trans($msgid);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry forget it won't work as the catalogue already loaded
@mpdude I think we must apply these changes into |
@aitboudad Some of the methods I changed/refactored are not yet available in 2.6. Do we really need to backport this? (Or maybe even move it to 2.8 instead?) |
@mpdude keeping the same test structure between branches makes the maintenance much easier for us when merging between branches (avoiding conflicts). So test improvements should be applied to the older versions being meaningful |
if some change are only relevant for |
…or tests. (mpdude) This PR was squashed before being merged into the 2.6 branch (closes #14437). Discussion ---------- [2.6][Translator] Extend, refactor and simplify Translator tests. | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | ~ | Tests pass? | yes | License | MIT These are the improvements from #14291 that we can easily backport to the 2.6 branch as requested [here](#14291 (comment)). Commits ------- a8c4471 [2.6][Translator] Extend, refactor and simplify Translator tests.
@mpdude you can rebase now |
@aitboudad Thanks for the heads-up |
This are the remaining changes on the 2.7 branch after #14437 merged most of the improvements into 2.6.
@xabbuh Done. (/cc @aitboudad) |
Thank you @mpdude. |
…r the Translator class (mpdude) This PR was merged into the 2.7 branch. Discussion ---------- [Translator]Test case refactoring and simplifications for the Translator class | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | ~ | Tests pass? | yes | License | MIT Also see #14280 and #14281. This also tests for the fix in [b5da2ae](b5da2ae#diff-3126bfacb25e1e304b8cc720e8527a19) Commits ------- c0300f5 Remaining tweaks for translator tests on 2.7
Also see #14280 and #14281.
This also tests for the fix in b5da2ae87606e1f47081d6e6f09dd61ccb6ab501