Completed
Push — master ( 84dee3...084275 )
by Michal
36:03
created

StatusTest::testFormatSpecified()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 24
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace Test\Phinx\Console\Command;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
use Symfony\Component\Console\Output\StreamOutput;
7
use Phinx\Config\Config;
8
use Phinx\Console\Command\Status;
9
10
class StatusTest extends \PHPUnit_Framework_TestCase
11
{
12
    protected $config = array();
13
14
    protected function setUp()
15
    {
16
        $this->config = new Config(array(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Phinx\Config\Config... '', 'port' => 5433)))) of type object<Phinx\Config\Config> is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
17
            'paths' => array(
18
                'migrations' => __FILE__,
19
            ),
20
            'environments' => array(
21
                'default_migration_table' => 'phinxlog',
22
                'default_database' => 'development',
23
                'development' => array(
24
                    'adapter' => 'pgsql',
25
                    'host' => 'fakehost',
26
                    'name' => 'development',
27
                    'user' => '',
28
                    'pass' => '',
29
                    'port' => 5433,
30
                )
31
            )
32
        ));
33
    }
34
35 View Code Duplication
    public function testExecute()
36
    {
37
        $application = new \Phinx\Console\PhinxApplication('testing');
38
        $application->add(new Status());
39
40
        // setup dependencies
41
        $output = new StreamOutput(fopen('php://memory', 'a', false));
42
43
        $command = $application->find('status');
44
45
        // mock the manager class
46
        $managerStub = $this->getMock('\Phinx\Migration\Manager', array(), array($this->config, $output));
47
        $managerStub->expects($this->once())
48
                    ->method('printStatus')
49
                    ->will($this->returnValue(0));
50
51
        $command->setConfig($this->config);
52
        $command->setManager($managerStub);
53
54
        $commandTester = new CommandTester($command);
55
        $return = $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
56
57
        $this->assertEquals(0, $return);
58
        $this->assertRegExp('/no environment specified/', $commandTester->getDisplay());
59
    }
60
61 View Code Duplication
    public function testExecuteWithEnvironmentOption()
62
    {
63
        $application = new \Phinx\Console\PhinxApplication('testing');
64
        $application->add(new Status());
65
66
        // setup dependencies
67
        $output = new StreamOutput(fopen('php://memory', 'a', false));
68
69
        $command = $application->find('status');
70
71
        // mock the manager class
72
        $managerStub = $this->getMock('\Phinx\Migration\Manager', array(), array($this->config, $output));
73
        $managerStub->expects($this->once())
74
                    ->method('printStatus')
75
                    ->will($this->returnValue(0));
76
77
        $command->setConfig($this->config);
78
        $command->setManager($managerStub);
79
80
        $commandTester = new CommandTester($command);
81
        $return = $commandTester->execute(array('command' => $command->getName(), '--environment' => 'fakeenv'), array('decorated' => false));
82
        $this->assertEquals(0, $return);
83
        $this->assertRegExp('/using environment fakeenv/', $commandTester->getDisplay());
84
    }
85
86 View Code Duplication
    public function testFormatSpecified()
87
    {
88
        $application = new \Phinx\Console\PhinxApplication('testing');
89
        $application->add(new Status());
90
91
        // setup dependencies
92
        $output = new StreamOutput(fopen('php://memory', 'a', false));
93
94
        $command = $application->find('status');
95
96
        // mock the manager class
97
        $managerStub = $this->getMock('\Phinx\Migration\Manager', array(), array($this->config, $output));
98
        $managerStub->expects($this->once())
99
                    ->method('printStatus')
100
                    ->will($this->returnValue(0));
101
102
        $command->setConfig($this->config);
103
        $command->setManager($managerStub);
104
105
        $commandTester = new CommandTester($command);
106
        $return = $commandTester->execute(array('command' => $command->getName(), '--format' => 'json'), array('decorated' => false));
107
        $this->assertEquals(0, $return);
108
        $this->assertRegExp('/using format json/', $commandTester->getDisplay());
109
    }
110
}
111