DumpCommandTest::getCompressedOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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