Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InstallerFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
15 use Zend\ServiceManager\ServiceLocatorInterface;
16 
20 class InstallerFactoryTest extends \PHPUnit\Framework\TestCase
21 {
25  private $objectManagerProviderMock;
26 
27  public function testCreate()
28  {
29  $this->objectManagerProviderMock = $this->getMockBuilder(\Magento\Setup\Model\ObjectManagerProvider::class)
30  ->disableOriginalConstructor()
31  ->setMethods(['get'])
32  ->getMock();
33 
34  $objectManagerMock = $this->getMockBuilder(ObjectManager::class)
35  ->disableOriginalConstructor()
36  ->setMethods(['get'])
37  ->getMock();
38  $objectManagerMock->expects($this->any())
39  ->method('get')
40  ->willReturnMap(
41  [
42  [DeclarationInstaller::class, $this->createMock(DeclarationInstaller::class)],
43  [SchemaPersistor::class, $this->createMock(SchemaPersistor::class)],
44  ]
45  );
46  $this->objectManagerProviderMock->expects($this->any())
47  ->method('get')
48  ->willReturn($objectManagerMock);
50  $serviceLocatorMock = $this->getMockForAbstractClass(
51  ServiceLocatorInterface::class,
52  ['get']
53  );
54  $serviceLocatorMock->expects($this->any())->method('get')
55  ->will($this->returnValueMap($this->getReturnValueMap()));
56 
58  $log = $this->getMockForAbstractClass(LoggerInterface::class);
60  $resourceFactoryMock = $this->createMock(ResourceFactory::class);
61  $resourceFactoryMock
62  ->expects($this->any())
63  ->method('create')
64  ->will($this->returnValue($this->createMock(\Magento\Framework\App\ResourceConnection::class)));
65  $installerFactory = new InstallerFactory($serviceLocatorMock, $resourceFactoryMock);
66  $installer = $installerFactory->create($log);
67  $this->assertInstanceOf(\Magento\Setup\Model\Installer::class, $installer);
68  }
69 
73  private function getReturnValueMap()
74  {
75  return [
76  [
77  \Magento\Framework\Setup\FilePermissions::class,
78  $this->createMock(\Magento\Framework\Setup\FilePermissions::class),
79  ],
80  [
81  \Magento\Framework\App\DeploymentConfig\Writer::class,
82  $this->createMock(\Magento\Framework\App\DeploymentConfig\Writer::class),
83  ],
84  [
85  \Magento\Framework\App\DeploymentConfig\Reader::class,
86  $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class),
87  ],
88  [
89  \Magento\Framework\App\DeploymentConfig::class,
90  $this->createMock(\Magento\Framework\App\DeploymentConfig::class),
91  ],
92  [
93  \Magento\Framework\Module\ModuleList::class,
94  $this->createMock(\Magento\Framework\Module\ModuleList::class),
95  ],
96  [
97  \Magento\Framework\Module\ModuleList\Loader::class,
98  $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class),
99  ],
100  [
101  \Magento\Setup\Model\AdminAccountFactory::class,
102  $this->createMock(\Magento\Setup\Model\AdminAccountFactory::class),
103  ],
104  [
105  \Magento\Setup\Module\ConnectionFactory::class,
106  $this->createMock(\Magento\Setup\Module\ConnectionFactory::class),
107  ],
108  [
109  \Magento\Framework\App\MaintenanceMode::class,
110  $this->createMock(\Magento\Framework\App\MaintenanceMode::class),
111  ],
112  [
113  \Magento\Framework\Filesystem::class,
114  $this->createMock(\Magento\Framework\Filesystem::class),
115  ],
116  [
117  \Magento\Setup\Model\ObjectManagerProvider::class,
118  $this->objectManagerProviderMock
119  ],
120  [
121  \Magento\Framework\Model\ResourceModel\Db\TransactionManager::class,
122  $this->createMock(\Magento\Framework\Model\ResourceModel\Db\TransactionManager::class),
123  ],
124  [
125  \Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor::class,
126  $this->createMock(\Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor::class),
127  ],
128  [
129  \Magento\Setup\Model\ConfigModel::class,
130  $this->createMock(\Magento\Setup\Model\ConfigModel::class),
131  ],
132  [
133  \Magento\Framework\App\State\CleanupFiles::class,
134  $this->createMock(\Magento\Framework\App\State\CleanupFiles::class),
135  ],
136  [
137  \Magento\Setup\Validator\DbValidator::class,
138  $this->createMock(\Magento\Setup\Validator\DbValidator::class),
139  ],
140  [
141  \Magento\Setup\Module\SetupFactory::class,
142  $this->createMock(\Magento\Setup\Module\SetupFactory::class),
143  ],
144  [
145  \Magento\Setup\Module\DataSetupFactory::class,
146  $this->createMock(\Magento\Setup\Module\DataSetupFactory::class),
147  ],
148  [
149  \Magento\Framework\Setup\SampleData\State::class,
150  $this->createMock(\Magento\Framework\Setup\SampleData\State::class),
151  ],
152  [
153  \Magento\Setup\Model\PhpReadinessCheck::class,
154  $this->createMock(\Magento\Setup\Model\PhpReadinessCheck::class),
155  ],
156  ];
157  }
158 }