Skip to content

Commit 7148511

Browse files
committed
[TranslationDebugCommand] fixed failing tests.
1 parent 90c80e3 commit 7148511

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,78 @@ public function testDebugMissingMessages()
2626
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo')));
2727
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
2828

29-
$this->assertRegExp('/x (\s|\|)+foo/', $tester->getDisplay(), 'Display x in case of missing message');
29+
$this->assertRegExp('/missing/', $tester->getDisplay());
3030
}
3131

3232
public function testDebugUnusedMessages()
3333
{
3434
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
3535
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
3636

37-
$this->assertRegExp('/o (\s|\|)+foo/', $tester->getDisplay(), 'Display o in case of unused message');
37+
$this->assertRegExp('/unused/', $tester->getDisplay());
3838
}
3939

4040
public function testDebugFallbackMessages()
4141
{
4242
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
4343
$tester->execute(array('locale' => 'fr', 'bundle' => 'foo'));
4444

45-
$this->assertRegExp('/= (\s|\|)+foo/', $tester->getDisplay(), 'Display = in case of fallback message');
45+
$this->assertRegExp('/fallback/', $tester->getDisplay());
4646
}
4747

4848
public function testNoDefinedMessages()
4949
{
5050
$tester = $this->createCommandTester($this->getContainer());
5151
$tester->execute(array('locale' => 'fr', 'bundle' => 'test'));
5252

53-
$this->assertRegExp('/^No defined or extracted messages for locale "fr"/', $tester->getDisplay());
53+
$this->assertRegExp('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
54+
}
55+
56+
public function testDebugDefaultDirectory()
57+
{
58+
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'), array('bar' => 'bar')));
59+
$tester->execute(array('locale' => 'en'));
60+
61+
$this->assertRegExp('/missing/', $tester->getDisplay());
62+
$this->assertRegExp('/unused/', $tester->getDisplay());
63+
}
64+
65+
public function testDebugCustomDirectory()
66+
{
67+
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
68+
$kernel->expects($this->once())
69+
->method('getBundle')
70+
->with($this->equalTo($this->translationDir))
71+
->willThrowException(new \InvalidArgumentException());
72+
73+
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo'), array('bar' => 'bar'), $kernel));
74+
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir));
75+
76+
$this->assertRegExp('/missing/', $tester->getDisplay());
77+
$this->assertRegExp('/unused/', $tester->getDisplay());
78+
}
79+
80+
/**
81+
* @expectedException \InvalidArgumentException
82+
*/
83+
public function testDebugInvalidDirectory()
84+
{
85+
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
86+
$kernel->expects($this->once())
87+
->method('getBundle')
88+
->with($this->equalTo('dir'))
89+
->will($this->throwException(new \InvalidArgumentException()));
90+
91+
$tester = $this->createCommandTester($this->getContainer(array(), array(), $kernel));
92+
$tester->execute(array('locale' => 'en', 'bundle' => 'dir'));
5493
}
5594

5695
protected function setUp()
5796
{
5897
$this->fs = new Filesystem();
5998
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation');
6099
$this->fs->mkdir($this->translationDir.'/Resources/translations');
100+
$this->fs->mkdir($this->translationDir.'/Resources/views');
61101
}
62102

63103
protected function tearDown()
@@ -79,7 +119,7 @@ private function createCommandTester($container)
79119
return new CommandTester($application->find('debug:translation'));
80120
}
81121

82-
private function getContainer($extractedMessages = array(), $loadedMessages = array())
122+
private function getContainer($extractedMessages = array(), $loadedMessages = array(), $kernel = null)
83123
{
84124
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
85125
->disableOriginalConstructor()
@@ -110,14 +150,21 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar
110150
})
111151
);
112152

113-
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
153+
if (null === $kernel) {
154+
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
155+
$kernel
156+
->expects($this->any())
157+
->method('getBundle')
158+
->will($this->returnValueMap(array(
159+
array('foo', true, $this->getBundle($this->translationDir)),
160+
array('test', true, $this->getBundle('test')),
161+
)));
162+
}
163+
114164
$kernel
115165
->expects($this->any())
116-
->method('getBundle')
117-
->will($this->returnValueMap(array(
118-
array('foo', true, $this->getBundle($this->translationDir)),
119-
array('test', true, $this->getBundle('test')),
120-
)));
166+
->method('getRootDir')
167+
->will($this->returnValue($this->translationDir));
121168

122169
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
123170
$container

0 commit comments

Comments
 (0)