/**
  * Removes module from setup_module table
  *
  * @param OutputInterface $output
  * @param string[] $modules
  * @return void
  */
 public function removeModulesFromDb(OutputInterface $output, array $modules)
 {
     $output->writeln('<info>Removing ' . implode(', ', $modules) . ' from module registry in database</info>');
     /** @var \Magento\Framework\Setup\ModuleDataSetupInterface $setup */
     $setup = $this->dataSetupFactory->create();
     foreach ($modules as $module) {
         $setup->deleteTableRow('setup_module', 'module', $module);
     }
 }
 public function testCreate()
 {
     $resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $context = $this->getMock('Magento\\Framework\\Module\\Setup\\Context', [], [], '', false);
     $context->expects($this->once())->method('getEventManager');
     $context->expects($this->once())->method('getLogger');
     $context->expects($this->once())->method('getMigrationFactory');
     $context->expects($this->once())->method('getResourceModel')->willReturn($resource);
     $context->expects($this->once())->method('getFilesystem')->willReturn($filesystem);
     $objectManager = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface', [], '', false);
     $objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Module\\Setup\\Context')->willReturn($context);
     $objectManagerProvider = $this->getMock('Magento\\Setup\\Model\\ObjectManagerProvider', [], [], '', false);
     $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
     $factory = new DataSetupFactory($objectManagerProvider);
     $this->assertInstanceOf('Magento\\Setup\\Module\\DataSetup', $factory->create());
 }
 /**
  * Collect Uninstall classes from modules
  *
  * @param array $filterModules
  * @return UninstallInterface[]
  */
 public function collectUninstall($filterModules = [])
 {
     $uninstallList = [];
     /** @var \Magento\Setup\Module\DataSetup $setup */
     $setup = $this->dataSetupFactory->create();
     $result = $setup->getConnection()->select()->from($setup->getTable('setup_module'), ['module']);
     if (isset($filterModules) && sizeof($filterModules) > 0) {
         $result->where('module in( ? )', implode(',', $filterModules));
     }
     // go through modules
     foreach ($setup->getConnection()->fetchAll($result) as $row) {
         $uninstallClassName = str_replace('_', '\\', $row['module']) . '\\Setup\\Uninstall';
         if (class_exists($uninstallClassName)) {
             $uninstallClass = $this->objectManager->create($uninstallClassName);
             if (is_subclass_of($uninstallClass, 'Magento\\Framework\\Setup\\UninstallInterface')) {
                 $uninstallList[$row['module']] = $uninstallClass;
             }
         }
     }
     return $uninstallList;
 }
示例#4
0
    public function testInstall()
    {
        $request = [
            ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1',
            ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento',
            ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento',
            ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key',
            ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend',
        ];
        $this->config->expects($this->atLeastOnce())
            ->method('get')
            ->willReturnMap(
                [
                    [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
                    [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
                ]
            );
        $allModules = ['Foo_One' => [], 'Bar_Two' => []];
        $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
        $setup = $this->getMock('Magento\Setup\Module\Setup', [], [], '', false);
        $table = $this->getMock('Magento\Framework\DB\Ddl\Table', [], [], '', false);
        $connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface');
        $setup->expects($this->any())->method('getConnection')->willReturn($connection);
        $table->expects($this->any())->method('addColumn')->willReturn($table);
        $table->expects($this->any())->method('setComment')->willReturn($table);
        $table->expects($this->any())->method('addIndex')->willReturn($table);
        $connection->expects($this->any())->method('newTable')->willReturn($table);
        $resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
        $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource);
        $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
        $dataSetup = $this->getMock('Magento\Setup\Module\DataSetup', [], [], '', false);
        $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
        $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
        $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
        $cacheManager->expects($this->any())->method('clean');
        $appState = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
            'Magento\Framework\App\State'
        );
        $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
        $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
        $this->objectManager->expects($this->any())
            ->method('create')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\Cache\Manager', [], $cacheManager],
                ['Magento\Framework\App\State', [], $appState],
            ]));
        $this->objectManager->expects($this->any())
            ->method('get')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\State', $appState],
                ['Magento\Framework\App\Cache\Manager', $cacheManager]
            ]));
        $this->adminFactory->expects($this->once())->method('create')->willReturn(
            $this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false)
        );
        $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
        $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
            ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
        );

        $this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:');
        $this->logger->expects($this->at(1))->method('log')->with('File permissions check...');
        $this->logger->expects($this->at(3))->method('log')->with('Required extensions check...');
        // at(2) invokes logMeta()
        $this->logger->expects($this->at(5))->method('log')->with('Enabling Maintenance Mode...');
        // at(4) - logMeta and so on...
        $this->logger->expects($this->at(7))->method('log')->with('Installing deployment configuration...');
        $this->logger->expects($this->at(9))->method('log')->with('Installing database schema:');
        $this->logger->expects($this->at(11))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(13))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(15))->method('log')->with('Schema post-updates:');
        $this->logger->expects($this->at(16))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(18))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(21))->method('log')->with('Installing user configuration...');
        $this->logger->expects($this->at(23))->method('log')->with('Enabling caches:');
        $this->logger->expects($this->at(27))->method('log')->with('Installing data...');
        $this->logger->expects($this->at(28))->method('log')->with('Data install/update:');
        $this->logger->expects($this->at(29))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(31))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(33))->method('log')->with('Data post-updates:');
        $this->logger->expects($this->at(34))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(36))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(39))->method('log')->with('Installing admin user...');
        $this->logger->expects($this->at(41))->method('log')->with('Caches clearing:');
        $this->logger->expects($this->at(44))->method('log')->with('Disabling Maintenance Mode:');
        $this->logger->expects($this->at(46))->method('log')->with('Post installation file permissions check...');
        $this->logger->expects($this->at(48))->method('log')->with('Write installation date...');
        $this->logger->expects($this->at(50))->method('logSuccess')->with('Magento installation complete.');
        $this->logger->expects($this->at(52))->method('log')
            ->with('Sample Data is installed with errors. See log file for details');
        $this->object->install($request);
    }
 /**
  * Installs data fixtures
  *
  * @return void
  * @throws \Exception
  */
 public function installDataFixtures()
 {
     $setup = $this->dataSetupFactory->create();
     $this->checkInstallationFilePermissions();
     $this->log->log('Data install/update:');
     $this->handleDBSchemaData($setup, 'data');
 }