|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Velikonja\LabbyBundle\Test\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
6
|
|
|
use Velikonja\LabbyBundle\Command\DumpCommand; |
|
7
|
|
|
|
|
8
|
|
|
class DumpCommandTest extends CommandTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Test simple execute of dump command to standard output. |
|
12
|
|
|
*/ |
|
13
|
|
|
public function testExecuteToStandardOutput() |
|
14
|
|
|
{ |
|
15
|
|
|
$exitCode = $this->tester->run( |
|
16
|
|
|
array( |
|
17
|
|
|
'command' => DumpCommand::COMMAND_NAME |
|
18
|
|
|
), |
|
19
|
|
|
array( |
|
20
|
|
|
'verbosity' => OutputInterface::VERBOSITY_DEBUG |
|
21
|
|
|
) |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
$display = trim($this->tester->getDisplay()); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals(0, $exitCode, $display); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertRegExp( |
|
29
|
|
|
'/-- Dump completed on/', |
|
30
|
|
|
$display, |
|
31
|
|
|
'Wrong output of dump command detected. Did it print the SQL dump?' |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Test simple execute of dump command to file. |
|
37
|
|
|
* |
|
38
|
|
|
* @param bool $compress |
|
39
|
|
|
* |
|
40
|
|
|
* @dataProvider getCompressedOptions |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testExecuteToFile($compress) |
|
43
|
|
|
{ |
|
44
|
|
|
$fileExt = $compress ? 'zip' : 'sql'; |
|
45
|
|
|
$path = $this->tmpDir . '/dump-to-file-test.' . $fileExt; |
|
46
|
|
|
|
|
47
|
|
|
$exitCode = $this->tester->run( |
|
48
|
|
|
array( |
|
49
|
|
|
'command' => DumpCommand::COMMAND_NAME, |
|
50
|
|
|
'file' => $path, |
|
51
|
|
|
'--compress' => $compress, |
|
52
|
|
|
), |
|
53
|
|
|
array( |
|
54
|
|
|
'verbosity' => OutputInterface::VERBOSITY_DEBUG |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$display = trim($this->tester->getDisplay()); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertEquals(0, $exitCode, $display); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertRegExp( |
|
63
|
|
|
sprintf('/%s`!$/', basename($path)), |
|
64
|
|
|
$display, |
|
65
|
|
|
'Wrong output of dump command detected.' |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertFileExists($path, sprintf('File was not dumped to `%s`.', $path)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return array|boolean[][] |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCompressedOptions() |
|
75
|
|
|
{ |
|
76
|
|
|
return array( |
|
77
|
|
|
array(false), |
|
78
|
|
|
array(true), |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|