1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Tests\Functional\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
15
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
16
|
|
|
use Translation\Bundle\Command\SyncCommand; |
17
|
|
|
use Translation\Bundle\Tests\Functional\BaseTestCase; |
18
|
|
|
|
19
|
|
|
class SyncCommandTest extends BaseTestCase |
20
|
|
|
{ |
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yaml'); |
25
|
|
|
|
26
|
|
|
\file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' |
27
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
28
|
|
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US"> |
29
|
|
|
<file id="messages.en_US"> |
30
|
|
|
<unit id="xx1"> |
31
|
|
|
<segment> |
32
|
|
|
<source>translated.heading</source> |
33
|
|
|
<target>My translated heading</target> |
34
|
|
|
</segment> |
35
|
|
|
</unit> |
36
|
|
|
<unit id="xx2"> |
37
|
|
|
<segment> |
38
|
|
|
<source>translated.paragraph0</source> |
39
|
|
|
<target>My translated paragraph0</target> |
40
|
|
|
</segment> |
41
|
|
|
</unit> |
42
|
|
|
<unit id="xx3"> |
43
|
|
|
<notes> |
44
|
|
|
<note category="file-source" priority="1">foobar.html.twig:9</note> |
45
|
|
|
</notes> |
46
|
|
|
<segment> |
47
|
|
|
<source>translated.paragraph1</source> |
48
|
|
|
<target>My translated paragraph1</target> |
49
|
|
|
</segment> |
50
|
|
|
</unit> |
51
|
|
|
<unit id="xx4"> |
52
|
|
|
<segment> |
53
|
|
|
<source>not.in.source</source> |
54
|
|
|
<target>This is not in the source code</target> |
55
|
|
|
</segment> |
56
|
|
|
</unit> |
57
|
|
|
</file> |
58
|
|
|
</xliff> |
59
|
|
|
|
60
|
|
|
XML |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testExecute(): void |
65
|
|
|
{ |
66
|
|
|
$this->bootKernel(); |
67
|
|
|
$application = new Application($this->kernel); |
68
|
|
|
|
69
|
|
|
$container = $this->getContainer(); |
70
|
|
|
$application->add($container->get(SyncCommand::class)); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$command = $application->find('translation:sync'); |
73
|
|
|
$commandTester = new CommandTester($command); |
74
|
|
|
|
75
|
|
|
try { |
76
|
|
|
$commandTester->execute([ |
77
|
|
|
'command' => $command->getName(), |
78
|
|
|
'configuration' => 'fail', |
79
|
|
|
]); |
80
|
|
|
|
81
|
|
|
$this->fail('The command should fail when called with an unknown configuration key.'); |
82
|
|
|
} catch (\InvalidArgumentException $e) { |
83
|
|
|
$this->assertRegExp('|Unknown storage "fail"\.|s', $e->getMessage()); |
84
|
|
|
$this->assertRegExp('|Available storages are "app"|s', $e->getMessage()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|