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(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.