/** * 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()); }
/** * Setup DirectoryList, Filesystem, and ComposerJsonFinder to use a specified directory for reading composer files * * @param $composerDir string Directory under _files that contains composer files */ private function setupDirectory($composerDir) { $absoluteComposerDir = realpath(__DIR__ . '/_files/' . $composerDir . '/composer.json'); $this->composerJsonFinder = $this->getMockBuilder('Magento\\Framework\\Composer\\ComposerJsonFinder')->disableOriginalConstructor()->setMethods([])->getMock(); $this->composerJsonFinder->expects($this->any())->method('findComposerJson')->willReturn($absoluteComposerDir); $this->directoryList = $this->objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList'); $this->filesystem = $this->objectManager->get('Magento\\Framework\\Filesystem'); /** @var \Magento\Framework\Composer\ComposerInformation $composerInfo */ $this->composerInformation = $this->objectManager->create('Magento\\Framework\\Composer\\ComposerInformation', ['applicationFactory' => new MagentoComposerApplicationFactory($this->composerJsonFinder, $this->directoryList)]); }
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); }
/** * Get Product version * * @return string * @throws \Exception */ public function getVersion() { if (!$this->version) { $composerJsonFile = $this->composerJsonFinder->findComposerJson(); $composerContent = file_get_contents($composerJsonFile); if ($composerContent === false) { throw new \Exception('Composer file content is empty'); } $composerContent = json_decode($composerContent, true); if (!$composerContent || !is_array($composerContent) || !array_key_exists('version', $composerContent)) { throw new \Exception('Unable to decode Composer file'); } $this->version = $composerContent['version']; } return $this->version; }
/** * 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]; } }
/** * Constructor * * @param ComposerJsonFinder $composerJsonFinder * @param DirectoryList $directoryList */ public function __construct(ComposerJsonFinder $composerJsonFinder, DirectoryList $directoryList) { $this->pathToComposerJson = $composerJsonFinder->findComposerJson(); $this->pathToComposerHome = $directoryList->getPath(DirectoryList::COMPOSER_HOME); }