Completed
Pull Request — master (#4)
by Timothy
14:57
created

CheckMigrationsUpToDateFactoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Abacaphiliac\DoctrineORMDiagnosticsModuleTest;
4
5
use Abacaphiliac\DoctrineORMDiagnosticsModule\CheckCommand;
6
use Abacaphiliac\DoctrineORMDiagnosticsModule\CheckMigrations\CheckMigrationsUpToDateFactory;
7
use Doctrine\DBAL\Migrations\Configuration\Configuration;
8
use Doctrine\DBAL\Migrations\Tools\Console\Command\UpToDateCommand;
9
use DoctrineModule\ServiceFactory\AbstractDoctrineServiceFactory;
10
use DoctrineORMModule\Service\MigrationsCommandFactory;
11
use Zend\Console\Request;
12
use Zend\ServiceManager\ServiceManager;
13
14
/**
15
 * @covers \Abacaphiliac\DoctrineORMDiagnosticsModule\CheckMigrations\CheckMigrationsUpToDateFactory
16
 */
17
class CheckMigrationsUpToDateFactoryTest extends \PHPUnit_Framework_TestCase
18
{
19
    /** @var \PHPUnit_Framework_MockObject_MockObject|Configuration */
20
    private $migrationsConfiguration;
21
    
22
    /** @var Request */
23
    private $request;
24
    
25
    /** @var \PHPUnit_Framework_MockObject_MockObject|UpToDateCommand */
26
    private $command;
27
    
28
    /** @var ServiceManager */
29
    private $serviceLocator;
30
    
31
    /** @var CheckMigrationsUpToDateFactory */
32
    private $sut;
33
34
    protected function setUp()
35
    {
36
        parent::setUp();
37
38
        $this->serviceLocator = new ServiceManager();
39
        $this->serviceLocator->addAbstractFactory(AbstractDoctrineServiceFactory::class);
40
        
41
        $this->command = $this->getMockBuilder(UpToDateCommand::class)
42
            ->disableOriginalConstructor()
43
            ->getMock();
44
45
        $this->migrationsConfiguration = $this->getMockBuilder(Configuration::class)
46
            ->disableOriginalConstructor()
47
            ->getMock();
48
        
49
        $this->request = new Request();
50
        
51
        $this->sut = new CheckMigrationsUpToDateFactory();
52
    }
53
    
54
    public function testCreateService()
55
    {
56
        $this->serviceLocator->setService('doctrine.migrations_cmd.uptodate', $this->command);
57
        $this->serviceLocator->setService('Request', $this->request);
58
        
59
        $actual = $this->sut->createService($this->serviceLocator);
60
        
61
        self::assertInstanceOf(CheckCommand::class, $actual);
62
    }
63
    
64
    public function testCreateServiceCollaborationTest()
65
    {
66
        $this->serviceLocator->setService('config', [
67
            'doctrine_factories' => [
68
                'migrations_cmd' => MigrationsCommandFactory::class,
69
            ],
70
            'doctrine' => [
71
                'migrations_cmd' => [
72
                    'uptodate' => [],
73
                ],
74
            ],
75
        ]);
76
        $this->serviceLocator->setService(
77
            'doctrine.migrations_configuration.orm_default',
78
            $this->migrationsConfiguration
79
        );
80
        $this->serviceLocator->setService('Request', $this->request);
81
        
82
        $actual = $this->sut->createService($this->serviceLocator);
83
        
84
        self::assertInstanceOf(CheckCommand::class, $actual);
85
    }
86
}
87