InstallerFactoryTest.php 6.34 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Setup\Test\Unit\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Setup\LoggerInterface;
use Magento\Framework\Setup\SchemaPersistor;
use Magento\Setup\Model\DeclarationInstaller;
use Magento\Setup\Model\InstallerFactory;
use Magento\Setup\Module\ResourceFactory;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class InstallerFactoryTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\Setup\Model\ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject
     */
    private $objectManagerProviderMock;

    public function testCreate()
    {
        $this->objectManagerProviderMock = $this->getMockBuilder(\Magento\Setup\Model\ObjectManagerProvider::class)
            ->disableOriginalConstructor()
            ->setMethods(['get'])
            ->getMock();

        $objectManagerMock = $this->getMockBuilder(ObjectManager::class)
            ->disableOriginalConstructor()
            ->setMethods(['get'])
            ->getMock();
        $objectManagerMock->expects($this->any())
            ->method('get')
            ->willReturnMap(
                [
                    [DeclarationInstaller::class, $this->createMock(DeclarationInstaller::class)],
                    [SchemaPersistor::class, $this->createMock(SchemaPersistor::class)],
                ]
            );
        $this->objectManagerProviderMock->expects($this->any())
            ->method('get')
            ->willReturn($objectManagerMock);
        /** @var ServiceLocatorInterface|\PHPUnit_Framework_MockObject_MockObject $serviceLocatorMock */
        $serviceLocatorMock = $this->getMockForAbstractClass(
            ServiceLocatorInterface::class,
            ['get']
        );
        $serviceLocatorMock->expects($this->any())->method('get')
            ->will($this->returnValueMap($this->getReturnValueMap()));

        /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $log */
        $log = $this->getMockForAbstractClass(LoggerInterface::class);
        /** @var ResourceFactory|\PHPUnit_Framework_MockObject_MockObject $resourceFactoryMock */
        $resourceFactoryMock = $this->createMock(ResourceFactory::class);
        $resourceFactoryMock
            ->expects($this->any())
            ->method('create')
            ->will($this->returnValue($this->createMock(\Magento\Framework\App\ResourceConnection::class)));
        $installerFactory = new InstallerFactory($serviceLocatorMock, $resourceFactoryMock);
        $installer = $installerFactory->create($log);
        $this->assertInstanceOf(\Magento\Setup\Model\Installer::class, $installer);
    }

    /**
     * @return array
     */
    private function getReturnValueMap()
    {
        return [
            [
                \Magento\Framework\Setup\FilePermissions::class,
                $this->createMock(\Magento\Framework\Setup\FilePermissions::class),
            ],
            [
                \Magento\Framework\App\DeploymentConfig\Writer::class,
                $this->createMock(\Magento\Framework\App\DeploymentConfig\Writer::class),
            ],
            [
                \Magento\Framework\App\DeploymentConfig\Reader::class,
                $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class),
            ],
            [
                \Magento\Framework\App\DeploymentConfig::class,
                $this->createMock(\Magento\Framework\App\DeploymentConfig::class),
            ],
            [
                \Magento\Framework\Module\ModuleList::class,
                $this->createMock(\Magento\Framework\Module\ModuleList::class),
            ],
            [
                \Magento\Framework\Module\ModuleList\Loader::class,
                $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class),
            ],
            [
                \Magento\Setup\Model\AdminAccountFactory::class,
                $this->createMock(\Magento\Setup\Model\AdminAccountFactory::class),
            ],
            [
                \Magento\Setup\Module\ConnectionFactory::class,
                $this->createMock(\Magento\Setup\Module\ConnectionFactory::class),
            ],
            [
                \Magento\Framework\App\MaintenanceMode::class,
                $this->createMock(\Magento\Framework\App\MaintenanceMode::class),
            ],
            [
                \Magento\Framework\Filesystem::class,
                $this->createMock(\Magento\Framework\Filesystem::class),
            ],
            [
                \Magento\Setup\Model\ObjectManagerProvider::class,
                $this->objectManagerProviderMock
            ],
            [
                \Magento\Framework\Model\ResourceModel\Db\TransactionManager::class,
                $this->createMock(\Magento\Framework\Model\ResourceModel\Db\TransactionManager::class),
            ],
            [
                \Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor::class,
                $this->createMock(\Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor::class),
            ],
            [
                \Magento\Setup\Model\ConfigModel::class,
                $this->createMock(\Magento\Setup\Model\ConfigModel::class),
            ],
            [
                \Magento\Framework\App\State\CleanupFiles::class,
                $this->createMock(\Magento\Framework\App\State\CleanupFiles::class),
            ],
            [
                \Magento\Setup\Validator\DbValidator::class,
                $this->createMock(\Magento\Setup\Validator\DbValidator::class),
            ],
            [
                \Magento\Setup\Module\SetupFactory::class,
                $this->createMock(\Magento\Setup\Module\SetupFactory::class),
            ],
            [
                \Magento\Setup\Module\DataSetupFactory::class,
                $this->createMock(\Magento\Setup\Module\DataSetupFactory::class),
            ],
            [
                \Magento\Framework\Setup\SampleData\State::class,
                $this->createMock(\Magento\Framework\Setup\SampleData\State::class),
            ],
            [
                \Magento\Setup\Model\PhpReadinessCheck::class,
                $this->createMock(\Magento\Setup\Model\PhpReadinessCheck::class),
            ],
        ];
    }
}