minor #14611 [TranslationDebugCommand] fixed failing tests. (aitboudad)
This PR was merged into the 2.7 branch.
Discussion
----------
[TranslationDebugCommand] fixed failing tests.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Fixed tickets | #14523
| Tests pass? | yes
| License | MIT
Commits
-------
f75790a
[TranslationDebugCommand] fixed failing tests.
This commit is contained in:
commit
2815ae8f93
|
@ -26,7 +26,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo')));
|
||||
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
|
||||
|
||||
$this->assertRegExp('/x (\s|\|)+foo/', $tester->getDisplay(), 'Display x in case of missing message');
|
||||
$this->assertRegExp('/missing/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDebugUnusedMessages()
|
||||
|
@ -34,7 +34,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
|
||||
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
|
||||
|
||||
$this->assertRegExp('/o (\s|\|)+foo/', $tester->getDisplay(), 'Display o in case of unused message');
|
||||
$this->assertRegExp('/unused/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDebugFallbackMessages()
|
||||
|
@ -42,7 +42,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
|
||||
$tester->execute(array('locale' => 'fr', 'bundle' => 'foo'));
|
||||
|
||||
$this->assertRegExp('/= (\s|\|)+foo/', $tester->getDisplay(), 'Display = in case of fallback message');
|
||||
$this->assertRegExp('/fallback/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testNoDefinedMessages()
|
||||
|
@ -50,7 +50,46 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
$tester = $this->createCommandTester($this->getContainer());
|
||||
$tester->execute(array('locale' => 'fr', 'bundle' => 'test'));
|
||||
|
||||
$this->assertRegExp('/^No defined or extracted messages for locale "fr"/', $tester->getDisplay());
|
||||
$this->assertRegExp('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDebugDefaultDirectory()
|
||||
{
|
||||
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'), array('bar' => 'bar')));
|
||||
$tester->execute(array('locale' => 'en'));
|
||||
|
||||
$this->assertRegExp('/missing/', $tester->getDisplay());
|
||||
$this->assertRegExp('/unused/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testDebugCustomDirectory()
|
||||
{
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
$kernel->expects($this->once())
|
||||
->method('getBundle')
|
||||
->with($this->equalTo($this->translationDir))
|
||||
->willThrowException(new \InvalidArgumentException());
|
||||
|
||||
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'), array('bar' => 'bar'), $kernel));
|
||||
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir));
|
||||
|
||||
$this->assertRegExp('/missing/', $tester->getDisplay());
|
||||
$this->assertRegExp('/unused/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testDebugInvalidDirectory()
|
||||
{
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
$kernel->expects($this->once())
|
||||
->method('getBundle')
|
||||
->with($this->equalTo('dir'))
|
||||
->will($this->throwException(new \InvalidArgumentException()));
|
||||
|
||||
$tester = $this->createCommandTester($this->getContainer(array(), array(), $kernel));
|
||||
$tester->execute(array('locale' => 'en', 'bundle' => 'dir'));
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
@ -58,6 +97,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
$this->fs = new Filesystem();
|
||||
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation');
|
||||
$this->fs->mkdir($this->translationDir.'/Resources/translations');
|
||||
$this->fs->mkdir($this->translationDir.'/Resources/views');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
|
@ -79,7 +119,7 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
return new CommandTester($application->find('debug:translation'));
|
||||
}
|
||||
|
||||
private function getContainer($extractedMessages = array(), $loadedMessages = array())
|
||||
private function getContainer($extractedMessages = array(), $loadedMessages = array(), $kernel = null)
|
||||
{
|
||||
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -110,14 +150,21 @@ class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
|
|||
})
|
||||
);
|
||||
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
if (null === $kernel) {
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('getBundle')
|
||||
->will($this->returnValueMap(array(
|
||||
array('foo', true, $this->getBundle($this->translationDir)),
|
||||
array('test', true, $this->getBundle('test')),
|
||||
)));
|
||||
}
|
||||
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('getBundle')
|
||||
->will($this->returnValueMap(array(
|
||||
array('foo', true, $this->getBundle($this->translationDir)),
|
||||
array('test', true, $this->getBundle('test')),
|
||||
)));
|
||||
->method('getRootDir')
|
||||
->will($this->returnValue($this->translationDir));
|
||||
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$container
|
||||
|
|
Reference in New Issue