-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Added template for relative file paths in FileDumper #9852
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Dumper; | ||
|
||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
/** | ||
* Null file dumper used for testing purposes. | ||
* | ||
* @author Florian Voutzinos <florian@voutzinos.com> | ||
*/ | ||
class NullFileDumper extends FileDumper | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function format(MessageCatalogue $messages, $domain) | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getExtension() | ||
{ | ||
return 'null'; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the idea of having a class in "prod" namespace just for testing purposes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that dumping is already covered by tests. What you should do is to test the behaviour of changing the template (if you change the template, result is dumped to a different file). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dumping is partially covered in the respective adapters but the backup (copy) and directories creation logic are not (from the abstract
The same question applies to test the logic of changing the template because it is done in the abstract There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the adapters tests could be refactored to only test the formatting logic. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Tests\Dumper; | ||
|
||
use Symfony\Component\Translation\Dumper\NullFileDumper; | ||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
class NullFileDumperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDumpBackupsFileIfExisting() | ||
{ | ||
$tempDir = sys_get_temp_dir(); | ||
$file = $tempDir.'/messages.en.null'; | ||
$backupFile = $file.'~'; | ||
|
||
@touch($file); | ||
|
||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar')); | ||
|
||
$dumper = new NullFileDumper(); | ||
$dumper->dump($catalogue, array('path' => $tempDir)); | ||
|
||
$this->assertTrue(file_exists($backupFile)); | ||
|
||
@unlink($file); | ||
@unlink($backupFile); | ||
} | ||
|
||
public function testDumpCreatesNestedDirectoriesAndFile() | ||
{ | ||
$tempDir = sys_get_temp_dir(); | ||
$translationsDir = $tempDir.'/test/translations'; | ||
$file = $translationsDir.'/messages.en.null'; | ||
|
||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar')); | ||
|
||
$dumper = new NullFileDumper(); | ||
$dumper->setRelativePathTemplate('test/translations/{domain}.{locale}.{extension}'); | ||
$dumper->dump($catalogue, array('path' => $tempDir)); | ||
|
||
$this->assertTrue(file_exists($file)); | ||
|
||
@unlink($file); | ||
@rmdir($translationsDir); | ||
} | ||
} |
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.
Does it need to be public or do we only need it internally?
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.
Actually this method is only used in a test and could be removed.
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 think it can be useful to be able to inspect the template that is currently set.
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 tend to agree with @jakzal. Exposing this information from the Dumper does not seem like a good idea. Again, most of the time, the default just work fine, so if you override it, it means that this information is already managed somewhere else.