/** * {@inheritdoc} */ public function execute() { $this->maintenanceMode->set(true); $this->backup->execute(); try { $this->status->add('Starting composer update...'); foreach ($this->params as $directive => $params) { $this->composerManager->updateComposerConfigFile($directive, $params); } $this->composerManager->runUpdate(); $this->status->setUpdateError(false); $this->maintenanceMode->set(false); $this->status->add('Composer update completed successfully'); } catch (\Exception $e) { $this->status->setUpdateError(true); try { $this->rollback->execute(); $this->status->setUpdateError(false); $this->maintenanceMode->set(false); } catch (\Exception $e) { throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage())); } throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage())); } $this->flushMagentoCache(); return $this; }
public function testUpdateComposerConfigFileAddNewDependency() { $testPackageName = 'magento/module-admin-notification'; $testPackageVersion = '0.74.0-beta2'; $expectedRequireDirectiveParam = [[ComposerManager::PACKAGE_NAME => $testPackageName, ComposerManager::PACKAGE_VERSION => $testPackageVersion]]; $this->composerManager->updateComposerConfigFile('require', $expectedRequireDirectiveParam); $fileJsonFormat = json_decode(file_get_contents($this->composerConfigFilePath), true); // Assert that dependency is removed from "replace" $this->assertEmpty($fileJsonFormat['replace']); // Assert that dependency is added to "require" $actualRequireDirective = $fileJsonFormat['require']; $this->assertTrue(array_key_exists($testPackageName, $actualRequireDirective)); $this->assertEquals($testPackageVersion, $actualRequireDirective[$testPackageName]); }