/** * Loads the configuration file * * @param string $fileKey * @return array * @throws \Exception */ public function load($fileKey = null) { $path = $this->dirList->getPath(DirectoryList::CONFIG); if ($fileKey) { $result = @(include $path . '/' . $this->configFilePool->getPath($fileKey)); } else { $configFiles = $this->configFilePool->getPaths(); $result = []; foreach (array_keys($configFiles) as $fileKey) { $configFile = $path . '/' . $this->configFilePool->getPath($fileKey); $fileData = @(include $configFile); if (!empty($fileData)) { $intersection = array_intersect_key($result, $fileData); if (!empty($intersection)) { $displayList = ''; foreach (array_keys($intersection) as $key) { $displayList .= $key . PHP_EOL; } throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayList); } $result = array_merge($result, $fileData); } } } return $result ?: []; }
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Module\ModuleList $moduleList, \Magento\Framework\App\Config\MutableScopeConfigInterface $scopeConfig, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\Session\SessionManagerInterface $session, \Wyomind\Core\Helper\Data $coreHelper, \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead, \Magento\Framework\Filesystem\File\ReadFactory $fileRead, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { parent::__construct($context, $registry, $resource, $resourceCollection, $data); $this->_magentoVersion = $coreHelper->getMagentoVersion(); $this->_moduleList = $moduleList; $this->_scopeConfig = $scopeConfig; $this->_urlBuilder = $urlBuilder; $this->_cacheManager = $context->getCacheManager(); $this->_session = $session; $this->_coreHelper = $coreHelper; $root = $directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::ROOT); if (file_exists($root . "/vendor/wyomind/")) { $this->_directoryRead = $directoryRead->create($root . "/vendor/wyomind/"); } else { $this->_directoryRead = $directoryRead->create($root . "/app/code/Wyomind/"); } $this->_httpRead = $fileRead; $this->_directoryList = $directoryList; $this->_version = $this->_moduleList->getOne("Wyomind_Core")['setup_version']; $this->_refreshCache = false; $this->getValues(); foreach ($this->_values as $ext) { $this->checkActivation($ext); } if ($this->_refreshCache) { $this->_cacheManager->clean(['config']); } }
/** * Create \Composer\Composer * * @return \Composer\Composer * @throws \Exception */ public function create() { if (!getenv('COMPOSER_HOME')) { putenv('COMPOSER_HOME=' . $this->directoryList->getPath(DirectoryList::COMPOSER_HOME)); } return \Composer\Factory::create(new BufferIO(), $this->composerJsonFinder->findComposerJson()); }
/** * Check var/generation read and write access * * @return bool */ public function check() { $initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $directoryList = new DirectoryList(BP, $filesystemDirPaths); $generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION); $driverPool = new DriverPool(); $fileWriteFactory = new WriteFactory($driverPool); /** @var \Magento\Framework\Filesystem\DriverInterface $driver */ $driver = $driverPool->getDriver(DriverPool::FILE); $directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath); if ($directoryWrite->isExist()) { if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) { try { $probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp'; $fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w'); $driver->deleteFile($probeFilePath); } catch (\Exception $e) { return false; } } else { return false; } } else { try { $directoryWrite->create(); } catch (\Exception $e) { return false; } } return true; }
/** * Run 'composer remove' * * @param array $packages * @return void */ public function remove(array $packages) { $this->composerApp->resetComposer(); $this->composerApp->setAutoExit(false); $vendor = (include $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php'); $this->composerApp->run(new ArrayInput(['command' => 'remove', 'packages' => $packages, '--working-dir' => $this->directoryList->getRoot() . '/' . $vendor . '/..'])); }
/** * Loads the configuration file * * @param string $fileKey * @return array * @throws \Exception */ public function load($fileKey = null) { $path = $this->dirList->getPath(DirectoryList::CONFIG); $fileDriver = $this->driverPool->getDriver(DriverPool::FILE); $result = []; if ($fileKey) { $filePath = $path . '/' . $this->configFilePool->getPath($fileKey); if ($fileDriver->isExists($filePath)) { $result = (include $filePath); } } else { $configFiles = $this->configFilePool->getPaths(); $allFilesData = []; $result = []; foreach (array_keys($configFiles) as $fileKey) { $configFile = $path . '/' . $this->configFilePool->getPath($fileKey); if ($fileDriver->isExists($configFile)) { $fileData = (include $configFile); } else { continue; } $allFilesData[$configFile] = $fileData; if (!empty($fileData)) { $intersection = array_intersect_key($result, $fileData); if (!empty($intersection)) { $displayMessage = $this->findFilesWithKeys(array_keys($intersection), $allFilesData); throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayMessage); } $result = array_merge($result, $fileData); } } } return $result ?: []; }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir, \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * Find absolute path to root Composer json file * * @return string * @throws \Exception */ public function findComposerJson() { $composerJson = $this->directoryList->getPath(DirectoryList::ROOT) . '/composer.json'; $composerJson = realpath($composerJson); if ($composerJson === false) { throw new \Exception('Composer file not found'); } return $composerJson; }
/** * Loads the configuration file * * @param string $configFile * @return array */ public function load($configFile = null) { if ($configFile) { $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $configFile; } else { $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file; } $result = @(include $file); return $result ?: []; }
/** * Retrieve list of recommended non-writable directories for application * * @return array */ public function getApplicationNonWritableDirectories() { if (!$this->applicationNonWritableDirectories) { $data = [DirectoryList::CONFIG]; foreach ($data as $code) { $this->applicationNonWritableDirectories[$code] = $this->directoryList->getPath($code); } } return array_values($this->applicationNonWritableDirectories); }
public function testDirectoriesCustomization() { $config = [DirectoryList::APP => [DirectoryList::PATH => 'foo', DirectoryList::URL_PATH => 'bar']]; $object = new DirectoryList('/root/dir', $config); $this->assertFileExists($object->getPath(DirectoryList::SYS_TMP)); $this->assertEquals('/root/dir/foo', $object->getPath(DirectoryList::APP)); $this->assertEquals('bar', $object->getUrlPath(DirectoryList::APP)); $this->setExpectedException('\\Magento\\Framework\\Filesystem\\FilesystemException', "Unknown directory type: 'unknown'"); $object->getPath('unknown'); }
public function testGetTranslationFileTimestamp() { $path = 'path'; $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']); $this->assetRepoMock->expects($this->atLeastOnce())->method('getStaticViewFileContext')->willReturn($contextMock); $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path); $this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path); $this->driverFileMock->expects($this->once())->method('isExists')->with('path/path/js-translation.json')->willReturn(true); $this->driverFileMock->expects($this->once())->method('stat')->willReturn(['mtime' => 1445736974]); $this->assertEquals(1445736974, $this->model->getTranslationFileTimestamp()); }
public function testCheckActionWithError() { $this->directoryList->expects($this->once())->method('getPath')->willReturn(__DIR__); $this->filesystem->expects($this->once())->method('validateAvailableDiscSpace')->will($this->throwException(new \Exception("Test error message"))); $jsonModel = $this->controller->checkAction(); $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('responseType', $variables); $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']); $this->assertArrayHasKey('error', $variables); $this->assertEquals("Test error message", $variables['error']); }
/** * Find absolute path to root Composer json file * * @return string * @throws \Exception */ public function findComposerJson() { // composer.json is in same directory as vendor $vendorPath = $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php'; $vendorDir = (require "{$vendorPath}"); $composerJson = $this->directoryList->getPath(DirectoryList::ROOT) . "/{$vendorDir}/../composer.json"; $composerJson = realpath($composerJson); if ($composerJson === false) { throw new \Exception('Composer file not found'); } return $composerJson; }
/** * File constructor. * * @param Data $helper * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList * @param \Magento\Framework\Filesystem $filesystem */ public function __construct(\Dotdigitalgroup\Email\Helper\Data $helper, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem $filesystem) { $this->helper = $helper; $this->directoryList = $directoryList; $this->filesystem = $filesystem; $var = $directoryList->getPath('var'); $this->outputFolder = $var . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email'; $this->outputArchiveFolder = $this->outputFolder . DIRECTORY_SEPARATOR . 'archive'; $this->delimiter = ','; // tab character $this->enclosure = '"'; }
public function setUp() { $this->composerJsonFinder = $this->getMock('Magento\\Framework\\Composer\\ComposerJsonFinder', [], [], '', false); $this->composerJsonFinder->expects($this->once())->method('findComposerJson')->willReturn('composer.json'); $this->directoryList = $this->getMock('Magento\\Framework\\App\\Filesystem\\DirectoryList', [], [], '', false); $this->directoryList->expects($this->exactly(2))->method('getPath')->willReturn('var'); $this->reqUpdDryRunCommand = $this->getMock('Magento\\Composer\\RequireUpdateDryRunCommand', [], [], '', false); $this->file = $this->getMock('Magento\\Framework\\Filesystem\\Driver\\File', [], [], '', false); $this->file->expects($this->once())->method('copy')->with('composer.json', 'var/composer.json'); $composerAppFactory = $this->getMock('Magento\\Framework\\Composer\\MagentoComposerApplicationFactory', [], [], '', false); $composerAppFactory->expects($this->once())->method('createRequireUpdateDryRunCommand')->willReturn($this->reqUpdDryRunCommand); $this->dependencyReadinessCheck = new DependencyReadinessCheck($this->composerJsonFinder, $this->directoryList, $this->file, $composerAppFactory); }
public function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Framework\App\Filesystem $filesystem */ $filesystem = $objectManager->create('Magento\\Framework\\App\\Filesystem', array('directoryList' => $objectManager->create('Magento\\Framework\\App\\Filesystem\\DirectoryList', array('root' => BP, 'directories' => array(\Magento\Framework\App\Filesystem::MODULES_DIR => array('path' => __DIR__ . '/_files/code'), \Magento\Framework\App\Filesystem::THEMES_DIR => array('path' => __DIR__ . '/_files/design'), \Magento\Framework\App\Filesystem::CONFIG_DIR => array('path' => __DIR__ . '/_files/')))))); $moduleListMock = $this->getMockBuilder('Magento\\Framework\\Module\\ModuleListInterface')->disableOriginalConstructor()->getMock(); $moduleListMock->expects($this->any())->method('getModules')->will($this->returnValue(array('Magento_Test' => array('name' => 'Magento_Test', 'version' => '1.11.1', 'active' => 'true')))); $moduleReader = $objectManager->create('Magento\\Framework\\Module\\Dir\\Reader', array('moduleList' => $moduleListMock, 'filesystem' => $filesystem)); $moduleReader->setModuleDir('Magento_Test', 'etc', __DIR__ . '/_files/code/Magento/Test/etc'); $this->_object = $objectManager->create('Magento\\Widget\\Model\\Config\\FileResolver', array('moduleReader' => $moduleReader, 'filesystem' => $filesystem)); $this->directoryList = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList'); $dirPath = ltrim(str_replace($this->directoryList->getRoot(), '', str_replace('\\', '/', __DIR__)) . '/_files', '/'); $this->directoryList->addDirectory(\Magento\Framework\App\Filesystem::MODULES_DIR, array('path' => $dirPath)); }
/** * @param AutoloaderInterface $autoloader * @param DirectoryList $dirList * @return void */ public static function populateMappings(AutoloaderInterface $autoloader, DirectoryList $dirList) { $generationDir = $dirList->getPath(DirectoryList::GENERATION); $frameworkDir = $dirList->getPath(DirectoryList::LIB_INTERNAL); $autoloader->addPsr4('Magento\\', [$generationDir . '/Magento/'], true); $autoloader->addPsr0('Cm_', $frameworkDir, true); $autoloader->addPsr0('Credis_', $frameworkDir, true); /** Required for Zend functionality */ FileResolver::addIncludePath($frameworkDir); /** Required for code generation to occur */ FileResolver::addIncludePath($generationDir); /** Required to autoload custom classes */ $autoloader->addPsr0('', [$generationDir]); }
public function add($contentFile, $cssFile) { $styleContent = preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', file_get_contents($contentFile)); if (empty($styleContent)) { return; } $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA); file_put_contents("{$mediaDir}/{$cssFile}", $styleContent, FILE_APPEND); $linkText = sprintf('<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}%s" />', $cssFile); $miscScriptsNode = 'design/head/includes'; $miscScripts = $this->scopeConfig->getValue($miscScriptsNode); if (!$miscScripts || strpos($miscScripts, $linkText) === false) { $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText); $this->configCacheType->clean(); } }
/** * Check all sub-directories and files except for var/generation and var/di * * @param string $directory * @return bool */ private function checkRecursiveDirectories($directory) { $directoryIterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST ); $noWritableFilesFolders = [ $this->directoryList->getPath(DirectoryList::GENERATION) . '/', $this->directoryList->getPath(DirectoryList::DI) . '/', ]; $directoryIterator = new Filter($directoryIterator, $noWritableFilesFolders); $directoryIterator = new ExcludeFilter( $directoryIterator, [ $this->directoryList->getPath(DirectoryList::SESSION) . '/', ] ); $foundNonWritable = false; try { foreach ($directoryIterator as $subDirectory) { if (!$subDirectory->isWritable() && !$subDirectory->isLink()) { $this->nonWritablePathsInDirectories[$directory][] = $subDirectory; $foundNonWritable = true; } } } catch (\UnexpectedValueException $e) { return false; } return !$foundNonWritable; }
public function setUpDirectoryListInstallation() { $this->directoryListMock->expects($this->at(0))->method('getPath')->with(DirectoryList::CONFIG)->will($this->returnValue(BP . '/app/etc')); $this->directoryListMock->expects($this->at(1))->method('getPath')->with(DirectoryList::VAR_DIR)->will($this->returnValue(BP . '/var')); $this->directoryListMock->expects($this->at(2))->method('getPath')->with(DirectoryList::MEDIA)->will($this->returnValue(BP . '/pub/media')); $this->directoryListMock->expects($this->at(3))->method('getPath')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue(BP . '/pub/static')); }
/** * Add Link to Head * * @return void */ protected function addHeadInclude() { $styleContent = ''; foreach ($this->moduleList->getNames() as $moduleName) { $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/styles.css'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } $style = file_get_contents($fileName); $styleContent .= preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', $style); } if (empty($styleContent)) { return; } $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA); file_put_contents("{$mediaDir}/styles.css", $styleContent); $linkTemplate = '<link rel="stylesheet" type="text/css" media="all" href="%sstyles.css" />'; $baseUrl = $this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]); $linkText = sprintf($linkTemplate, $baseUrl); $miscScriptsNode = 'design/head/includes'; $miscScripts = $this->scopeConfig->getValue($miscScriptsNode); if (!$miscScripts || strpos($miscScripts, $linkText) === false) { $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText); $this->configCacheType->clean(); } }
/** * Checks dependencies to package(s), returns array of dependencies in the format of * 'package A' => [array of package names depending on package A] * If $excludeSelf is set to true, items in $packages will be excluded in all * "array of package names depending on package A" * * @param string[] $packages * @param bool $excludeSelf * @return string[] */ public function checkDependencies(array $packages, $excludeSelf = false) { $this->composerApp->setAutoExit(false); $dependencies = []; foreach ($packages as $package) { $buffer = new BufferedOutput(); $this->composerApp->resetComposer(); $this->composerApp->run(new ArrayInput(['command' => 'depends', '--working-dir' => $this->directoryList->getRoot(), 'package' => $package]), $buffer); $dependingPackages = $this->parseComposerOutput($buffer->fetch()); if ($excludeSelf === true) { $dependingPackages = array_values(array_diff($dependingPackages, $packages)); } $dependencies[$package] = $dependingPackages; } return $dependencies; }
/** * Returns path to env.php file * * @return string * @throws \Exception */ private function getEnvPath() { $deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG); $configPool = new ConfigFilePool(); $envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV); return $envPath; }
/** * Get Vendors Path for sample-data-media package * * @return string */ protected function getVendorsMagentoMediaPath() { $vendorPathConfig = $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php'; if (!file_exists($vendorPathConfig)) { return null; } $vendorPath = (include $vendorPathConfig); $vendorsMagentoDir = $this->directoryList->getPath(DirectoryList::ROOT) . '/' . $vendorPath . '/magento'; if (!file_exists($vendorsMagentoDir)) { return null; } $vendorsMagentoMedia = $vendorsMagentoDir . '/sample-data-media'; if (file_exists($vendorsMagentoMedia)) { return $vendorsMagentoMedia; } return null; }
/** * Run Composer dependency check * * @param array $packages * @return array * @throws \Exception */ public function runReadinessCheck(array $packages) { $composerJson = $this->composerJsonFinder->findComposerJson(); $this->file->copy($composerJson, $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/composer.json'); $workingDir = $this->directoryList->getPath(DirectoryList::VAR_DIR); try { foreach ($packages as $package) { if (strpos($package, 'magento/product-enterprise-edition') !== false) { $this->magentoComposerApplication->runComposerCommand(['command' => 'remove', 'packages' => ['magento/product-community-edition'], '--no-update' => true], $workingDir); } } $this->requireUpdateDryRunCommand->run($packages, $workingDir); return ['success' => true]; } catch (\RuntimeException $e) { $message = str_replace(PHP_EOL, '<br/>', htmlspecialchars($e->getMessage())); return ['success' => false, 'error' => $message]; } }
public function setUp() { $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false); $this->log = $this->getMock('Magento\Framework\Setup\LoggerInterface', [], [], '', false); $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); $this->path = realpath(__DIR__); $this->directoryList->expects($this->any()) ->method('getRoot') ->willReturn($this->path); $this->directoryList->expects($this->any()) ->method('getPath') ->willReturn($this->path); $this->file = $this->getMock('Magento\Framework\Filesystem\Driver\File', [], [], '', false); $this->filesystem = $this->getMock('Magento\Framework\Backup\Filesystem', [], [], '', false); $this->database = $this->getMock('Magento\Framework\Backup\Db', [], [], '', false); $this->helper = $this->getMock('Magento\Framework\Backup\Filesystem\Helper', [], [], '', false); $this->helper->expects($this->any()) ->method('getInfo') ->willReturn(['writable' => true, 'size' => 100]); $configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false); $configLoader->expects($this->any()) ->method('load') ->willReturn([]); $this->objectManager->expects($this->any()) ->method('get') ->will($this->returnValueMap([ ['Magento\Framework\App\State', $this->getMock('Magento\Framework\App\State', [], [], '', false)], ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader], ])); $this->objectManager->expects($this->any()) ->method('create') ->will($this->returnValueMap([ ['Magento\Framework\Backup\Filesystem\Helper', [], $this->helper], ['Magento\Framework\Backup\Filesystem', [], $this->filesystem], ['Magento\Framework\Backup\Db', [], $this->database], ])); $this->model = new BackupRollback( $this->objectManager, $this->log, $this->directoryList, $this->file, $this->helper ); }
public function testExecute() { $this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\App\\Cache')->willReturn($this->cacheMock); $this->cacheMock->expects($this->once())->method('clean'); $writeDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface'); $writeDirectory->expects($this->atLeastOnce())->method('delete'); $this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory); $this->deploymentConfigMock->expects($this->once())->method('get')->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)->willReturn(['Magento_Catalog' => 1]); $progressBar = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\ProgressBar')->disableOriginalConstructor()->getMock(); $this->objectManagerMock->expects($this->once())->method('configure'); $this->objectManagerMock->expects($this->once())->method('create')->with('Symfony\\Component\\Console\\Helper\\ProgressBar')->willReturn($progressBar); $this->managerMock->expects($this->exactly(7))->method('addOperation'); $this->managerMock->expects($this->once())->method('process'); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertContains('Generated code and dependency injection configuration successfully.', explode(PHP_EOL, $tester->getDisplay())); $this->assertSame(DiCompileCommand::NAME, $this->command->getName()); }
/** * Create ObjectManager * * @param string $rootDir * @param array $arguments * @param bool $useCompiled * @return \Magento\Framework\ObjectManager * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function create($rootDir, array $arguments, $useCompiled = true) { $directories = isset($arguments[Filesystem::PARAM_APP_DIRS]) ? $arguments[Filesystem::PARAM_APP_DIRS] : array(); $directoryList = new DirectoryList($rootDir, $directories); (new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array($directoryList->getDir(Filesystem::GENERATION_DIR))); $appArguments = $this->createAppArguments($directoryList, $arguments); $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(new \Magento\Framework\Filesystem\Driver\File(), $directoryList->getDir(Filesystem::DI_DIR), $directoryList->getDir(Filesystem::GENERATION_DIR), $appArguments->get('definition.format', 'serialized')); $definitions = $definitionFactory->createClassDefinition($appArguments->get('definitions'), $useCompiled); $relations = $definitionFactory->createRelations(); $configClass = $this->_configClassName; /** @var \Magento\Framework\ObjectManager\Config\Config $diConfig */ $diConfig = new $configClass($relations, $definitions); $appMode = $appArguments->get(State::PARAM_MODE, State::MODE_DEFAULT); $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils(); $argInterpreter = $this->createArgumentInterpreter($booleanUtils); $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter); $configData = $this->_loadPrimaryConfig($directoryList, $argumentMapper, $appMode); if ($configData) { $diConfig->extend($configData); } $this->factory = new \Magento\Framework\ObjectManager\Factory\Factory($diConfig, null, $definitions, $appArguments->get()); if ($appArguments->get('MAGE_PROFILER') == 2) { $this->factory = new \Magento\Framework\ObjectManager\Profiler\FactoryDecorator($this->factory, \Magento\Framework\ObjectManager\Profiler\Log::getInstance()); } $className = $this->_locatorClassName; $sharedInstances = ['Magento\\Framework\\App\\Arguments' => $appArguments, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\ObjectManager\\Relations' => $relations, 'Magento\\Framework\\Interception\\Definition' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\Config' => $diConfig, 'Magento\\Framework\\ObjectManager\\Definition' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, $configClass => $diConfig]; /** @var \Magento\Framework\ObjectManager $objectManager */ $objectManager = new $className($this->factory, $diConfig, $sharedInstances); $this->factory->setObjectManager($objectManager); ObjectManager::setInstance($objectManager); /** @var \Magento\Framework\App\Filesystem\DirectoryList\Verification $verification */ $verification = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Verification'); $verification->createAndVerifyDirectories(); $diConfig->setCache($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigCache')); $objectManager->configure($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigLoader')->load('global')); $objectManager->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope('global'); $objectManager->get('Magento\\Framework\\App\\Resource')->setCache($objectManager->get('Magento\\Framework\\App\\CacheInterface')); $interceptionConfig = $objectManager->get('Magento\\Framework\\Interception\\Config\\Config'); $diConfig->setInterceptionConfig($interceptionConfig); $this->configureDirectories($objectManager); return $objectManager; }