MigrateAllCommandFactoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 61
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testInvoke() 0 51 1
1
<?php
2
3
namespace ReddogsTest\Doctrine\Migrations;
4
5
use Interop\Container\ContainerInterface;
6
use Reddogs\Doctrine\Migrations\MigrateAllCommand;
7
use Reddogs\Doctrine\Migrations\MigrateAllCommandFactory;
8
use Doctrine\DBAL\Connection;
9
use Doctrine\ORM\EntityManager;
10
11
class MigrateAllCommandFactoryTest extends \PHPUnit_Framework_TestCase
12
{
13
    private $factory;
14
15
    protected function setUp()
16
    {
17
        $this->factory = new MigrateAllCommandFactory; 
18
    }
19
20
    public function testInvoke()
21
    {
22
        $container = $this->getMockBuilder(ContainerInterface::class)
23
            ->setMethods(['get', 'has'])
24
            ->getMock();
25
26
        $config = [
27
            'doctrine' => [
28
                'reddogs_doctrine_migrations' => [
29
                    'testkey' => [
30
                        'table_name' => 'testTableName',
31
                        'directory' => 'testDirectory',
32
                        'namespace' => 'TestNameSpace'
33
                    ]
34
                ]
35
            ]
36
        ];
37
38
        $container->expects($this->at(0))
39
            ->method('get')
40
            ->with($this->equalTo('config'))
41
            ->will($this->returnValue($config));
42
43
        $entityManager = $this->getMockBuilder(EntityManager::class)
44
            ->disableOriginalConstructor()
45
            ->setMethods(['getConnection'])
46
            ->getMock();
47
        $connection = $this->createMock(Connection::class);
48
        $entityManager->expects($this->once())
49
            ->method('getConnection')
50
            ->will($this->returnValue($connection));
51
        
52
53
        $container->expects($this->at(1))
54
            ->method('get')
55
            ->with($this->equalTo(EntityManager::class))
56
            ->will($this->returnValue($entityManager));
57
        
58
        $service = $this->factory->__invoke($container, MigrateAllCommand::class);
59
        
60
        $this->assertInstanceOf(MigrateAllCommand::class, $service);
61
        $configurations = $service->getConfigurations();
62
        $this->assertCount(1, $configurations);
63
        $this->assertArrayHasKey('testkey', $configurations);
64
65
        $this->assertSame('testTableName', $configurations['testkey']->getMigrationsTableName());
66
        $this->assertSame('testDirectory', $configurations['testkey']->getMigrationsDirectory());
67
        $this->assertSame('TestNameSpace', $configurations['testkey']->getMigrationsNamespace());
68
69
        $migrations = $service->getMigrations();
0 ignored issues
show
Unused Code introduced by
$migrations is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
    }
71
}