ImportCommandTest::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\ImportCommand;
7
8
class ImportCommandTest extends CommandTestCase
9
{
10
    /**
11
     * Test file not found.
12
     */
13
    public function testIfCommandFailsWhenFileIsNotFound()
14
    {
15
        $exitCode = $this->tester->run(
16
            array(
17
                'command' => ImportCommand::COMMAND_NAME,
18
                'file'    => '/non-existing-file.hopefully',
19
            )
20
        );
21
22
        $this->assertEquals(1, $exitCode, trim($this->tester->getDisplay()));
23
    }
24
25
    /**
26
     * Test simple execute of import command.
27
     *
28
     * @param bool $compress
29
     *
30
     * @dataProvider getCompressedOptions
31
     */
32
    public function testExecute($compress)
33
    {
34
        $fileExt = $compress ? 'zip' : 'sql';
35
        $path    = $this->getFixturesDir() . '/test-dump.' . $fileExt;
36
37
        $exitCode = $this->tester->run(
38
            array(
39
                'command' => ImportCommand::COMMAND_NAME,
40
                'file'    => $path,
41
            ),
42
            array(
43
                'verbosity' => OutputInterface::VERBOSITY_DEBUG
44
            )
45
        );
46
47
        $display = trim($this->tester->getDisplay());
48
49
        $this->assertEquals(0, $exitCode, $display);
50
51
        $this->assertRegExp(
52
            '/^Database successfully imported!$/',
53
            $display,
54
            'Wrong output of import command detected.'
55
        );
56
    }
57
58
    /**
59
     * @return array|boolean[][]
60
     */
61
    public function getCompressedOptions()
62
    {
63
        return array(
64
            array(false),
65
            array(true),
66
        );
67
    }
68
}
69