Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Merged
merged 1 commit into from
Apr 25, 2015
Merged

[Translator]Test case refactoring and simplifications for the Translator class #14291

merged 1 commit into from
Apr 25, 2015

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Apr 9, 2015

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 b5da2ae87606e1f47081d6e6f09dd61ccb6ab501


foreach (array(false, true) as $debug) {
// Prime the cache
$translator = new Translator($locale, null, $this->tmpDir);
Copy link
Contributor

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)

@aitboudad aitboudad changed the title Test case refactoring and simplifications for the Translator class [Translator]Test case refactoring and simplifications for the Translator class Apr 9, 2015
@aitboudad
Copy link
Contributor

the failed test for dep=high is not related to this PR.

@aitboudad
Copy link
Contributor

can you squash your commits into one, please

@mpdude
Copy link
Contributor Author

mpdude commented Apr 11, 2015

Done.

@linaori
Copy link
Contributor

linaori commented Apr 11, 2015

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.

@mpdude
Copy link
Contributor Author

mpdude commented Apr 11, 2015


~~~@aitboudad :-)?~~~

@mpdude
Copy link
Contributor Author

mpdude commented Apr 11, 2015

As the @dataProvider approach also allows to remove the deleteTmpDir() call, it's a good thing(TM).

Thanks @iltar!

@@ -466,11 +466,12 @@ private function getFallbackContent(MessageCatalogue $catalogue)
private function getCatalogueCachePath($locale)
{
$catalogueHash = sha1(serialize(array(
'locale' => $this->locale,
Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

@aitboudad
Copy link
Contributor

@mpdude can you squash your commits :)

@mpdude
Copy link
Contributor Author

mpdude commented Apr 13, 2015

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
Copy link
Contributor

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);

@mpdude
Copy link
Contributor Author

mpdude commented Apr 14, 2015

Hm, sounds a bit whacky, doesn't it?

But if you prefer I'll change that.

@aitboudad
Copy link
Contributor

@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);
Copy link
Contributor

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);

Copy link
Contributor

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

@aitboudad
Copy link
Contributor

@mpdude I think we must apply these changes into 2.6, can you create a PR for 2.6 in favor of this ?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2015

@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?)

@stof
Copy link
Member

stof commented Apr 21, 2015

@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

@aitboudad
Copy link
Contributor

if some change are only relevant for 2.7 you can keep it in this PR, I already do the same thing in #14341 (comment) ;)

@mpdude
Copy link
Contributor Author

mpdude commented Apr 22, 2015

See #14437. I'll probably need to rebase this one after #14437 is merged and makes it up into 2.7?

aitboudad added a commit that referenced this pull request Apr 22, 2015
…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.
@aitboudad
Copy link
Contributor

@mpdude you can rebase now

@mpdude
Copy link
Contributor Author

mpdude commented Apr 24, 2015

@aitboudad Thanks for the heads-up

@xabbuh
Copy link
Member

xabbuh commented Apr 24, 2015

@mpdude Can you rebase once again (tests have been fixed in #14464)?

This are the remaining changes on the 2.7 branch after #14437 merged most of the improvements into 2.6.
@mpdude
Copy link
Contributor Author

mpdude commented Apr 24, 2015

@xabbuh Done. (/cc @aitboudad)

@aitboudad
Copy link
Contributor

Thank you @mpdude.

@aitboudad aitboudad merged commit c0300f5 into symfony:2.7 Apr 25, 2015
aitboudad added a commit that referenced this pull request Apr 25, 2015
…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
@mpdude mpdude deleted the independent-translator-caches branch April 25, 2015 10:49
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.