public function testExecute() { /** * Check autoloading */ /* @var $application Application */ $application = (require __DIR__ . '/../../../src/bootstrap.php'); $application->setMagentoRootFolder($this->getTestMagentoRoot()); $this->assertInstanceOf('\\N98\\Magento\\Application', $application); $loader = $application->getAutoloader(); $this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader); /** * Check version */ $this->assertEquals(Application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt'))); /* @var $loader \Composer\Autoload\ClassLoader */ $prefixes = $loader->getPrefixes(); $this->assertArrayHasKey('N98', $prefixes); $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml')); $configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('ssl' => 'sys:store:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel'))); $application->setAutoExit(false); $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray)); $application->run(new StringInput('list'), new NullOutput()); // Check if autoloaders, commands and aliases are registered $prefixes = $loader->getPrefixes(); $this->assertArrayHasKey('N98MagerunTest', $prefixes); $testDummyCommand = $application->find('n98mageruntest:test:dummy'); $this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand); $commandTester = new CommandTester($testDummyCommand); $commandTester->execute(array('command' => $testDummyCommand->getName())); $this->assertContains('dummy', $commandTester->getDisplay()); $this->assertTrue($application->getDefinition()->hasOption('root-dir')); // check alias $this->assertInstanceOf('\\N98\\Magento\\Command\\System\\Store\\ListCommand', $application->find('ssl')); }
/** * Filter modules by codepool, status and vendor if such options were inputted by user * * @param InputInterface $input * @return Modules */ public function filterModules(InputInterface $input) { $filtered = $this->list; if ($input->getOption('codepool')) { $filtered = ArrayFunctions::matrixFilterByValue($filtered, "codePool", $input->getOption('codepool')); } if ($input->getOption('status')) { $filtered = ArrayFunctions::matrixFilterByValue($filtered, 'Status', $input->getOption('status')); } if ($input->getOption('vendor')) { $filtered = ArrayFunctions::matrixFilterStartswith($filtered, 'Name', $input->getOption('vendor')); } return new self($filtered); }
public function testExecute() { /** * Check autoloading */ /* @var $application Application */ $application = (require __DIR__ . '/../../../src/bootstrap.php'); $magentoRootFolder = getenv('N98_MAGERUN_TEST_MAGENTO_ROOT'); if (empty($magentoRootFolder)) { $this->markTestSkipped('Please specify environment variable N98_MAGERUN_TEST_MAGENTO_ROOT with path to your test ' . 'magento installation!'); } $application->setMagentoRootFolder($magentoRootFolder); $this->assertInstanceOf('\\N98\\Magento\\Application', $application); $loader = $application->getAutoloader(); $this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader); /** * Check version */ $this->assertEquals($application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt'))); /* @var $loader \Composer\Autoload\ClassLoader */ $prefixes = $loader->getPrefixes(); $this->assertArrayHasKey('N98', $prefixes); $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml')); $configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('cl' => 'cache:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel'))); $application->setAutoExit(false); $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray)); $application->run(new StringInput('list'), new NullOutput()); // Check if autoloaders, commands and aliases are registered $prefixes = $loader->getPrefixes(); $this->assertArrayHasKey('N98MagerunTest', $prefixes); $testDummyCommand = $application->find('n98mageruntest:test:dummy'); $this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand); $commandTester = new CommandTester($testDummyCommand); $commandTester->execute(array('command' => $testDummyCommand->getName())); $this->assertContains('dummy', $commandTester->getDisplay()); $this->assertTrue($application->getDefinition()->hasOption('root-dir')); // Test alternative config model $application->initMagento(); if (version_compare(\Mage::getVersion(), '1.7.0.2', '>=')) { // config_model option is only available in Magento CE >1.6 $this->assertInstanceOf('\\N98MagerunTest\\AlternativeConfigModel', \Mage::getConfig()); } // check alias $this->assertInstanceOf('\\N98\\Magento\\Command\\Cache\\ListCommand', $application->find('cl')); }
/** * MAGENTO_ROOT/app/etc/n98-magerun.yaml * * @param string $magentoRootFolder * @param string $magerunStopFileFolder * @param array $config * * @return array */ public function loadProjectConfig($magentoRootFolder, $magerunStopFileFolder, array $config) { if (null !== $this->_projectConfig) { return ArrayFunctions::mergeArrays($config, $this->_projectConfig); } $this->_projectConfig = array(); $locator = new ConfigLocator($this->_customConfigFilename, $magentoRootFolder); if ($projectConfigFile = $locator->getProjectConfigFile()) { $this->_projectConfig = $projectConfigFile->toArray(); } if ($stopFileConfigFile = $locator->getStopFileConfigFile($magerunStopFileFolder)) { $this->_projectConfig = $stopFileConfigFile->mergeArray($this->_projectConfig); } return ArrayFunctions::mergeArrays($config, $this->_projectConfig); }
/** * @param array $initConfig * @param OutputInterface $output * @return ConfigurationLoader */ public function getConfigurationLoader($initConfig = array(), OutputInterface $output) { if ($this->configurationLoader === null) { $this->configurationLoader = new ConfigurationLoader(ArrayFunctions::mergeArrays($this->config, $initConfig), $this->isPharMode(), $output); } return $this->configurationLoader; }
/** * Loads a plugin config file and merges it to plugin config * * @param string $magentoRootFolder * @param SplFileInfo $file */ protected function registerPluginConfigFile($magentoRootFolder, $file) { if (String::startsWith($file->getPathname(), 'vfs://')) { $path = $file->getPathname(); } else { $path = $file->getRealPath(); } if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) { $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>'); } $localPluginConfig = \file_get_contents($path); $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file)); $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig); }
public function mergeArray(array $array) { $result = $this->toArray(); return ArrayFunctions::mergeArrays($array, $result); }
/** * Loads a plugin config file and merges it to plugin config * * @param string $magentoRootFolder * @param SplFileInfo $file */ protected function registerPluginConfigFile($magentoRootFolder, $file) { if (BinaryString::startsWith($file->getPathname(), 'vfs://')) { $path = $file->getPathname(); } else { $path = $file->getRealPath(); if ($path === "") { throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file)); } if ($path === false) { $this->_output->writeln(sprintf("<error>Plugin config file broken link '%s'</error>", $file)); return; } } if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) { $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>'); } $localPluginConfig = \file_get_contents($path); $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file)); $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig); }
/** * @param array $initConfig * @param bool $isPharMode * @param OutputInterface $output * * @return ConfigurationLoader */ public function createLoader(array $initConfig, $isPharMode, OutputInterface $output) { $config = ArrayFunctions::mergeArrays($this->config, $initConfig); $loader = new ConfigurationLoader($config, $isPharMode, $output); return $loader; }
/** * @param bool $ignoreDataUpdate * @param array $headers * @param int $errorCount * @return array */ private function getModuleTable($ignoreDataUpdate, array $headers, &$errorCount) { $errorCount = 0; $table = array(); foreach ($this->getMagentoModuleList() as $name => $module) { $row = $this->mapModuleToRow($name, $module, $ignoreDataUpdate, $errorCount); if ($ignoreDataUpdate) { unset($row['Data']); } $table[] = ArrayFunctions::columnOrder($headers, $row); } return $table; }