testInvokeEmptyResultOutputsInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 9.0856
c 1
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace ReddogsTest\Doctrine\Migrations;
4
5
use Doctrine\DBAL\Migrations\Configuration\Configuration;
6
use Doctrine\DBAL\Migrations\Migration;
7
use Doctrine\DBAL\Migrations\OutputWriter;
8
use Reddogs\Doctrine\Migrations\MigrateAllCommand;
9
use Zend\Console\Adapter\AdapterInterface;
10
use ZF\Console\Route;
11
12
class MigrateAllCommandTest extends \PHPUnit_Framework_TestCase
13
{
14
    private $configurations, $migrations, $configuration, $migration;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
15
16
    protected function setUp()
17
    {
18
        $this->configuration = $this->getMockBuilder(Configuration::class)
19
            ->disableOriginalConstructor()
20
            ->setMethods(['createMigrationTable', 'setOutputWriter'])
21
            ->getMock();;
22
        $this->configurations = ['testKey' => $this->configuration];
23
24
        $this->migration = $this->getMockBuilder(Migration::class)
25
            ->disableOriginalConstructor()
26
            ->setMethods(['migrate'])
27
            ->getMock();
28
        $this->migrations = ['testKey' => $this->migration];
29
30
        $this->command = new MigrateAllCommand($this->configurations, $this->migrations);
0 ignored issues
show
Bug introduced by
The property command does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
    }
32
33
    public function testGetConfigurations()
34
    {
35
        $this->assertSame($this->configurations, $this->command->getConfigurations());
36
    }
37
38
    public function testGetMigrations()
39
    {
40
        $this->assertSame($this->migrations, $this->command->getMigrations());
41
    }
42
43
    public function testInvoke()
44
    {
45
        $this->configuration->expects($this->once())
46
            ->method('createMigrationTable');
47
48
        $this->configuration->expects($this->once())
49
            ->method('setOutputWriter')
50
            ->with($this->isInstanceOf(OutputWriter::class));
51
52
        $this->migration->expects($this->once())
53
            ->method('migrate')
54
            ->will($this->returnValue(['some result line']));
55
56
        $route = new Route('mogrations:migrate-all', 'mogrations:migrate-all <moduleName>');
57
        $adapter = $this->createMock(AdapterInterface::class);
58
        $this->command->__invoke($route, $adapter);
59
    }
60
61
    public function testInvokeEmptyResultOutputsInfo()
62
    {
63
        $this->configuration->expects($this->once())
64
            ->method('createMigrationTable');
65
66
        $this->configuration->expects($this->once())
67
            ->method('setOutputWriter')
68
            ->with($this->isInstanceOf(OutputWriter::class));
69
70
        $this->migration->expects($this->once())
71
            ->method('migrate')
72
            ->will($this->returnValue([]));
73
74
        $route = new Route('mogrations:migrate-all', 'mogrations:migrate-all <moduleName>');
75
        $adapter = $this->getMockBuilder(AdapterInterface::class)
76
            ->setMethods(['writeLine'])
77
            ->getMockForAbstractClass();
78
79
        $adapter->expects($this->once())
80
                ->method('writeLine')
81
                ->with($this->equalTo('module \'testKey\': no migrations to execute'));
82
        $this->command->__invoke($route, $adapter);
83
    }
84
}