public function testClearMaterializedViewFiles() { $static = $this->getDirectoryCleanMock(); $var = $this->getDirectoryCleanMock(DirectoryList::TMP_MATERIALIZATION_DIR); $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->will($this->returnValueMap([[DirectoryList::STATIC_VIEW, DriverPool::FILE, $static], [DirectoryList::VAR_DIR, DriverPool::FILE, $var]])); $this->object->clearMaterializedViewFiles(); }
/** * @param bool $isEnable * @param bool $clearStaticContent * @param string $expectedMessage * * @dataProvider executeDataProvider */ public function testExecute($isEnable, $clearStaticContent, $expectedMessage) { $this->status->expects($this->once()) ->method('getModulesToChange') ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) ->will($this->returnValue(['Magento_Module1'])); $this->status->expects($this->any()) ->method('checkConstraints') ->will($this->returnValue([])); $this->status->expects($this->once()) ->method('setIsEnabled') ->with($isEnable, ['Magento_Module1']); $this->cache->expects($this->once()) ->method('clean'); $this->cleanupFiles->expects($this->once()) ->method('clearCodeGeneratedClasses'); $this->cleanupFiles->expects($clearStaticContent ? $this->once() : $this->never()) ->method('clearMaterializedViewFiles'); $commandTester = $isEnable ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); $input = ['module' => ['Magento_Module1', 'Magento_Module2']]; if ($clearStaticContent) { $input['--clear-static-content'] = true; } $commandTester->execute($input); $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay()); }
/** * Do the cleanup * * @return void */ protected function performCleanup() { $this->status->add('Cleaning generated files...', \Psr\Log\LogLevel::INFO); $this->cleanupFiles->clearCodeGeneratedFiles(); $this->status->add('Complete!', \Psr\Log\LogLevel::INFO); $this->status->add('Clearing cache...', \Psr\Log\LogLevel::INFO); $this->cache->clean(); $this->status->add('Complete!', \Psr\Log\LogLevel::INFO); }
public function testExecuteCleanStaticFiles() { $this->setUpExecute(); $this->cleanupFiles->expects($this->once())->method('clearMaterializedViewFiles'); $this->tester->execute(['theme' => ['test'], '-c' => true]); $this->assertContains('Enabling maintenance mode', $this->tester->getDisplay()); $this->assertContains('Disabling maintenance mode', $this->tester->getDisplay()); $this->assertNotContains('Alert: Generated static view files were not cleared.', $this->tester->getDisplay()); $this->assertContains('Generated static view files cleared successfully', $this->tester->getDisplay()); }
public function testExecuteAll() { $input = ['module' => ['Magento_A', 'Magento_B'], '-c' => true, '-r' => true]; $this->setUpExecute(); $this->moduleUninstaller->expects($this->once())->method('uninstallData')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']); $this->moduleUninstaller->expects($this->once())->method('uninstallCode')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']); $this->moduleRegistryUninstaller->expects($this->once())->method('removeModulesFromDb')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']); $this->moduleRegistryUninstaller->expects($this->once())->method('removeModulesFromDeploymentConfig')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']); $this->cleanupFiles->expects($this->once())->method('clearMaterializedViewFiles'); $this->tester->execute($input); }
/** * Cleanup after updated modules status * * @param InputInterface $input * @param OutputInterface $output * @return void */ private function cleanup(InputInterface $input, OutputInterface $output) { $this->cache->clean(); $output->writeln('<info>Cache cleared successfully.</info>'); if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) { $this->cleanupFiles->clearMaterializedViewFiles(); $output->writeln('<info>Generated static view files cleared successfully.</info>'); } else { $output->writeln('<error>Alert: Generated static view files were not cleared.' . ' You can clear them using the --' . self::INPUT_KEY_CLEAR_STATIC_CONTENT . ' option.' . ' Failure to clear static view files might cause display issues in the Admin and storefront.</error>'); } }
public function testExecuteAll() { $input = ['module' => ['Magento_A', 'Magento_B'], '-c' => true, '-r' => true]; $this->setUpExecute($input); $this->cleanupFiles->expects($this->once())->method('clearMaterializedViewFiles'); $uninstallMock = $this->getMockForAbstractClass('Magento\Framework\Setup\UninstallInterface', [], '', false); $uninstallMock->expects($this->once()) ->method('uninstall') ->with($this->setup, $this->isInstanceOf('Magento\Setup\Model\ModuleContext')); $this->uninstallCollector->expects($this->once()) ->method('collectUninstall') ->willReturn(['Magento_A' => $uninstallMock]); $this->tester->execute($input); }
public function testUninstall() { $this->configReader->expects($this->once())->method('getFiles')->willReturn(['ConfigOne.php', 'ConfigTwo.php']); $configDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $configDir ->expects($this->exactly(2)) ->method('getAbsolutePath') ->will( $this->returnValueMap( [ ['ConfigOne.php', '/config/ConfigOne.php'], ['ConfigTwo.php', '/config/ConfigTwo.php'] ] ) ); $this->filesystem ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValueMap([ [DirectoryList::CONFIG, DriverPool::FILE, $configDir], ])); $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); $this->logger ->expects($this->at(2)) ->method('log') ->with('No database connection defined - skipping database cleanup'); $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); $cacheManager->expects($this->once())->method('clean'); $this->objectManager->expects($this->any()) ->method('get') ->with('Magento\Framework\App\Cache\Manager') ->willReturn($cacheManager); $this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully'); $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); $this->logger ->expects($this->at(4)) ->method('log') ->with("The directory '/var' doesn't exist - skipping cleanup"); $this->logger ->expects($this->at(5)) ->method('log') ->with("The directory '/static' doesn't exist - skipping cleanup"); $this->logger ->expects($this->at(6)) ->method('log') ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); $this->logger ->expects($this->at(7)) ->method('log') ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->will( $this->returnValue( [ "The directory '/var' doesn't exist - skipping cleanup", "The directory '/static' doesn't exist - skipping cleanup" ] ) ); $this->object->uninstall(); }
/** * Clear var/generation and reset object manager * * @return void */ private function cleanupGeneratedFiles() { $this->log->log('File system cleanup:'); $messages = $this->cleanupFiles->clearCodeGeneratedFiles(); // unload Magento autoloader because it may be using compiled definition foreach (spl_autoload_functions() as $autoloader) { if ($autoloader[0] instanceof \Magento\Framework\Code\Generator\Autoloader) { spl_autoload_unregister([$autoloader[0], $autoloader[1]]); break; } } // Corrected Magento autoloader will be loaded upon next get() call on $this->objectManagerProvider $this->objectManagerProvider->reset(); foreach ($messages as $message) { $this->log->log($message); } }
/** * Uninstall Magento application * * @return void */ public function uninstall() { $this->log->log('Starting Magento uninstallation:'); $this->cleanupDb(); $this->clearCache(); $this->log->log('File system cleanup:'); $messages = $this->cleanupFiles->clearAllFiles(); foreach ($messages as $message) { $this->log->log($message); } $this->deleteDeploymentConfig(); $this->log->logSuccess('Magento uninstallation complete.'); }