/** * Ensures that the rmt config section can be added to the composer file. */ public function testAddRmtConfigSection() { $config = \Liip\RMT\Config::create(array('vcs' => 'git', "prerequisites" => array("working-copy-check", "display-last-changes"), 'versionPersister' => "vcs-tag")); $serialized = $this->helper->addRMTConfigSection($config); $this->assertContains('vcs-tag', $serialized); $config = $this->helper->getRMTConfigSection(); $this->assertNotNull($config); $this->assertEquals('git', $config->getVcs(), var_export($config, true)); }
protected function initialize(InputInterface $input, OutputInterface $output) { $helper = new ComposerConfig(); $file = $this->getApplication()->getProjectRootDir() . '/composer.json'; $helper->setComposerFile($file); $config = $helper->getRMTConfigSection(); if (!$config) { return; } $this->writeBigTitle('Current: ' . $helper->getProjectName() . ' ' . $helper->getCurrentVersion()); $this->writeEmptyLine(); }
/** * Context factory method. * * @param \Liip\RMT\Application $application * @return \Liip\RMT\Context */ public static function create(Application $application) { $rootDir = $application->getProjectRootDir(); $helper = new Helpers\ComposerConfig(); $helper->setComposerFile($rootDir . '/composer.json'); $config = $helper->getRMTConfigSection(); $context = new Context(); $builder = new Helpers\ServiceBuilder($context); /* * The following services are config-dependent */ if ($config !== null) { if ($config->getVcs()) { $context->setService('vcs', $builder->getService($config->getVcs(), 'vcs')); } // Store the config for latter usage $context->setParameter('config', $config); /* * populate version persister */ $context->setService("version-persister", $builder->getService($config->getVersionPersister(), 'versionPersister')); $context->setService("version-detector", $builder->getService($config->getVersionDetector(), 'versionDetector')); /* * popluate lists */ foreach (array("prerequisites", self::PRERELEASE_LIST, "postReleaseActions") as $listName) { $context->createEmptyList($listName); foreach ($config->{$listName} as $service) { $context->addToList($listName, $builder->getService($service, $listName)); } } } // Provide the root dir as a context parameter $context->setParameter('project-root', $rootDir); return $context; }
/** * Returns the configuration. * * @return object * @throws NoConfigurationException */ public function getConfig() { $helper = new Helpers\ComposerConfig(); $file = $this->getProjectRootDir() . '/composer.json'; $helper->setComposerFile($file); $config = $helper->getRMTConfigSection(); if ($config === null) { throw new NoConfigurationException("Impossible to locate the extra/rmt config section in {$file}. If it's the first time you\n are using this tool, you need to setup your project using the [RMT init] command"); } return $config; }