public function testCheckDependenciesWhenEnableModulesWithCurEnabledModules()
 {
     $this->packageInfoMock->expects($this->atLeastOnce())->method('getNonExistingDependencies')->willReturn([]);
     $this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock);
     $actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D'], ['C']);
     $expected = ['B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']], 'D' => ['A' => ['D', 'A'], 'E' => ['D', 'A', 'B', 'E']]];
     $this->assertEquals($expected, $actual);
 }
Example #2
0
 public function load($modelId, $field = null)
 {
     parent::load($modelId, $field);
     $this->setId($modelId);
     // array_filter to remove empty items caused by non-magento modules requirements
     $this->setDepends(array_filter($this->packageInfo->getRequire($this->getCode())));
     $this->setVersion($this->packageInfo->getVersion($this->getCode()));
     $this->setPackageName($this->packageInfo->getPackageName($this->getCode()));
     return $this;
 }
 public function setUp()
 {
     $this->packageInfoMock = $this->getMock('Magento\\Framework\\Module\\PackageInfo', [], [], '', false);
     $requireMap = [['A', ['B']], ['B', ['D', 'E']], ['C', ['E']], ['D', ['A']], ['E', []]];
     $this->packageInfoMock->expects($this->any())->method('getRequire')->will($this->returnValueMap($requireMap));
     $this->packageInfoFactoryMock = $this->getMock('Magento\\Framework\\Module\\PackageInfoFactory', [], [], '', false);
     $this->packageInfoFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->packageInfoMock));
     $this->listMock = $this->getMock('Magento\\Framework\\Module\\ModuleList', [], [], '', false);
     $this->loaderMock = $this->getMock('Magento\\Framework\\Module\\ModuleList\\Loader', [], [], '', false);
     $this->loaderMock->expects($this->any())->method('load')->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []]));
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
     if (!empty($sampleDataPackages)) {
         foreach (array_keys($sampleDataPackages) as $name) {
             $moduleName = $this->packageInfo->getModuleName($name);
             $this->moduleResource->setDataVersion($moduleName, '');
         }
         $output->writeln('<info>' . 'Reset of sample data version completed successfully.' . '</info>');
     } else {
         $output->writeln('<info>' . 'There is no sample data for current set of modules.' . '</info>');
     }
 }
 private function setUpPassValidation()
 {
     $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
     $packageMap = [['Magento_A', 'magento/package-a'], ['Magento_B', 'magento/package-b']];
     $this->packageInfo->expects($this->any())->method('getPackageName')->will($this->returnValueMap($packageMap));
     $this->fullModuleList->expects($this->any())->method('has')->willReturn(true);
 }
 /**
  * Validate list of modules against installed composer packages and return error messages
  *
  * @param string[] $modules
  * @return string[]
  */
 protected function validate(array $modules)
 {
     $messages = [];
     $unknownPackages = [];
     $unknownModules = [];
     $installedPackages = $this->composer->getRootRequiredPackages();
     foreach ($modules as $module) {
         if (array_search($this->packageInfo->getPackageName($module), $installedPackages) === false) {
             $unknownPackages[] = $module;
         }
         if (!$this->fullModuleList->has($module)) {
             $unknownModules[] = $module;
         }
     }
     $unknownPackages = array_diff($unknownPackages, $unknownModules);
     if (!empty($unknownPackages)) {
         $text = count($unknownPackages) > 1 ?
             ' are not installed composer packages' : ' is not an installed composer package';
         $messages[] = '<error>' . implode(', ', $unknownPackages) . $text . '</error>';
     }
     if (!empty($unknownModules)) {
         $messages[] = '<error>Unknown module(s): ' . implode(', ', $unknownModules) . '</error>';
     }
     return $messages;
 }
 public function testComponentsAction()
 {
     $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface', [], [], '', false);
     $this->objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
     $objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Module\\PackageInfoFactory', $this->packageInfoFactoryMock], ['Magento\\Framework\\Module\\FullModuleList', $this->fullModuleListMock], ['Magento\\Framework\\Module\\ModuleList', $this->enabledModuleListMock]]);
     $this->packageInfoFactoryMock->expects($this->once())->method('create')->willReturn($this->packageInfo);
     $this->fullModuleListMock->expects($this->once())->method('getNames')->willReturn(['magento/sample-module1']);
     $this->packageInfo->expects($this->once())->method('getModuleName')->willReturn('Sample_Module');
     $this->packageInfo->expects($this->exactly(2))->method('getPackageName')->willReturn($this->componentData['magento/sample-module-one']['name']);
     $this->packageInfo->expects($this->exactly(2))->method('getVersion')->willReturn($this->componentData['magento/sample-module-one']['version']);
     $this->enabledModuleListMock->expects($this->once())->method('has')->willReturn(true);
     $this->composerInformationMock->expects($this->once())->method('getInstalledMagentoPackages')->willReturn($this->componentData);
     $this->composerInformationMock->expects($this->once())->method('isPackageInComposerJson')->willReturn(true);
     $this->packagesAuth->expects($this->once())->method('getAuthJsonData')->willReturn(['username' => 'someusername', 'password' => 'somepassword']);
     $this->packagesData->expects($this->once())->method('syncPackagesData')->willReturn($this->lastSyncData);
     $jsonModel = $this->controller->componentsAction();
     $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('success', $variables);
     $this->assertTrue($variables['success']);
     $expected = [['name' => 'magento/sample-module-one', 'type' => 'magento2-module', 'version' => '1.0.0', 'update' => false, 'uninstall' => true, 'vendor' => 'magento', 'moduleName' => 'Sample_Module', 'enable' => true, 'disable' => false]];
     $this->assertEquals($expected, $variables['components']);
     $this->assertArrayHasKey('total', $variables);
     $this->assertEquals(1, $variables['total']);
     $this->assertEquals($this->lastSyncData, $variables['lastSyncData']);
 }
 public function testGetVersion()
 {
     $this->assertEquals('0.1', $this->packageInfo->getVersion('A'));
     $this->assertEquals('0.2', $this->packageInfo->getVersion('B'));
     $this->assertEquals('0.1', $this->packageInfo->getVersion('C'));
     $this->assertEquals('0.3', $this->packageInfo->getVersion('D'));
     $this->assertEquals('0.4', $this->packageInfo->getVersion('E'));
     $this->assertEquals('', $this->packageInfo->getVersion('F'));
 }
 /**
  * Get full list of modules as an associative array
  *
  * @return array
  */
 private function getAllModules()
 {
     $modules = [];
     $allModules = $this->fullModuleList->getNames();
     foreach ($allModules as $module) {
         $moduleName = $this->packageInfo->getPackageName($module);
         $modules[$moduleName]['name'] = $moduleName;
         $modules[$moduleName]['type'] = \Magento\Framework\Composer\ComposerInformation::MODULE_PACKAGE_TYPE;
         $modules[$moduleName]['version'] = $this->packageInfo->getVersion($module);
     }
     return $modules;
 }
 /**
  * Create the dependency graph
  *
  * @return Graph
  */
 private function createGraph()
 {
     $nodes = [];
     $dependencies = [];
     // build the graph data
     foreach (array_keys($this->fullModuleList) as $moduleName) {
         $nodes[] = $moduleName;
         foreach ($this->packageInfo->getRequire($moduleName) as $dependModuleName) {
             if ($dependModuleName) {
                 $dependencies[] = [$moduleName, $dependModuleName];
             }
         }
     }
     $nodes = array_unique(array_merge($nodes, $this->packageInfo->getNonExistingDependencies()));
     return new Graph($nodes, $dependencies);
 }
Example #11
0
 public function testComponentsAction()
 {
     $this->fullModuleListMock->expects($this->once())
         ->method('getNames')
         ->willReturn(['magento/sample-module1']);
     $this->packageInfo->expects($this->once())
         ->method('getModuleName')
         ->willReturn('Sample_Module');
     $this->packageInfo->expects($this->exactly(2))
         ->method('getPackageName')
         ->willReturn($this->componentData['magento/sample-module-one']['name']);
     $this->packageInfo->expects($this->exactly(2))
         ->method('getVersion')
         ->willReturn($this->componentData['magento/sample-module-one']['version']);
     $this->enabledModuleListMock->expects($this->once())
         ->method('has')
         ->willReturn(true);
     $this->composerInformationMock->expects($this->once())
         ->method('getInstalledMagentoPackages')
         ->willReturn($this->componentData);
     $this->composerInformationMock->expects($this->once())
         ->method('isPackageInComposerJson')
         ->willReturn(true);
     $this->updatePackagesCacheMock->expects($this->once())
         ->method('getPackagesForUpdate')
         ->willReturn($this->lastSyncData);
     $jsonModel = $this->controller->componentsAction();
     $this->assertInstanceOf('Zend\View\Model\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('success', $variables);
     $this->assertTrue($variables['success']);
     $expected = [[
         'name' => 'magento/sample-module-one',
         'type' => 'magento2-module',
         'version' => '1.0.0',
         'update' => false,
         'uninstall' => true,
         'vendor' => 'magento',
         'moduleName' => 'Sample_Module',
         'enable' => true,
         'disable' => false
     ]];
     $this->assertEquals($expected, $variables['components']);
     $this->assertArrayHasKey('total', $variables);
     $this->assertEquals(1, $variables['total']);
     $this->assertEquals($this->lastSyncData, $variables['lastSyncData']);
 }
 /**
  * Check if two modules are conflicted and get the message for display
  *
  * @param string $moduleA
  * @param string $moduleB
  * @return string[]
  */
 private function getConflictMessages($moduleA, $moduleB)
 {
     $messages = [];
     $versionParser = new VersionParser();
     if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getConflict($moduleB)[$moduleA] && $this->packageInfo->getVersion($moduleA)) {
         $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]);
         $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA));
         if ($constraintA->matches($constraintB)) {
             $messages[] = "{$moduleB} conflicts with current {$moduleA} version " . $this->packageInfo->getVersion($moduleA) . ' (version should not be ' . $this->packageInfo->getConflict($moduleB)[$moduleA] . ')';
         }
     }
     if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && $this->packageInfo->getConflict($moduleA)[$moduleB] && $this->packageInfo->getVersion($moduleB)) {
         $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]);
         $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB));
         if ($constraintA->matches($constraintB)) {
             $messages[] = "{$moduleA} conflicts with current {$moduleB} version " . $this->packageInfo->getVersion($moduleA) . ' (version should not be ' . $this->packageInfo->getConflict($moduleA)[$moduleB] . ')';
         }
     }
     return $messages;
 }