1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EllipseSynergie\LocaleToYaml\Tests\Commands; |
4
|
|
|
|
5
|
|
|
use EllipseSynergie\LocaleToYaml\Commands\ExportCommand; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
use Symfony\Component\Console\Application; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ExportCommandTest |
11
|
|
|
* |
12
|
|
|
* @package EllipseSynergie\ApiResponse\Tests |
13
|
|
|
* @author Dominic Martineau <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ExportCommandTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
public function testExportSucceed() |
18
|
|
|
{ |
19
|
|
|
$application = new Application(); |
20
|
|
|
$application->add(new ExportCommand()); |
21
|
|
|
|
22
|
|
|
$command = $application->find('lang:export-to-yaml'); |
23
|
|
|
$commandTester = new CommandTester($command); |
24
|
|
|
$commandTester->execute(array( |
25
|
|
|
'command' => $command->getName(), |
26
|
|
|
'in' => 'tests/locale.php' |
27
|
|
|
)); |
28
|
|
|
|
29
|
|
|
// the output of the command in the console |
30
|
|
|
$output = $commandTester->getDisplay(); |
31
|
|
|
$this->assertContains('Exporting tests/locale.php to tests/locale.yaml', $output); |
32
|
|
|
|
33
|
|
|
// validate content |
34
|
|
|
$content = "foo: bar\n" . |
35
|
|
|
"hello:\n" . |
36
|
|
|
" world: 'Hello world!'\n" . |
37
|
|
|
" number: 666\n" . |
38
|
|
|
" three:\n" . |
39
|
|
|
" four: five\n" . |
40
|
|
|
" multi: |\n" . |
41
|
|
|
" This is a\n" . |
42
|
|
|
" multi line\n" . |
43
|
|
|
" sentence.\n"; |
44
|
|
|
$this->assertSame($content, file_get_contents('tests/locale.yaml')); |
45
|
|
|
|
46
|
|
|
// remove outputed file |
47
|
|
|
@unlink('tests/locale.yaml'); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @expectedException \Symfony\Component\Console\Exception\RuntimeException |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testExportWithWrongArguments() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$application = new Application(); |
56
|
|
|
$application->add(new ExportCommand()); |
57
|
|
|
|
58
|
|
|
$command = $application->find('lang:export-to-yaml'); |
59
|
|
|
$commandTester = new CommandTester($command); |
60
|
|
|
$commandTester->execute(array( |
61
|
|
|
'command' => $command->getName(), |
62
|
|
|
)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @expectedException \EllipseSynergie\LocaleToYaml\Exceptions\FileNotFoundException |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function testExportWithInvalidFilename() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$application = new Application(); |
71
|
|
|
$application->add(new ExportCommand()); |
72
|
|
|
|
73
|
|
|
$command = $application->find('lang:export-to-yaml'); |
74
|
|
|
$commandTester = new CommandTester($command); |
75
|
|
|
$commandTester->execute(array( |
76
|
|
|
'command' => $command->getName(), |
77
|
|
|
'in' => 'tests/foo.php' |
78
|
|
|
)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: