/** * @dataProvider provideInstaller */ public function testInstaller(PackageInterface $rootPackage, $repositories, array $options) { $io = $this->getMock('Composer\\IO\\IOInterface'); $downloadManager = $this->getMock('Composer\\Downloader\\DownloadManager'); $config = $this->getMock('Composer\\Config'); $repositoryManager = new RepositoryManager($io, $config); $repositoryManager->setLocalRepository(new WritableRepositoryMock()); $repositoryManager->setLocalDevRepository(new WritableRepositoryMock()); if (!is_array($repositories)) { $repositories = array($repositories); } foreach ($repositories as $repository) { $repositoryManager->addRepository($repository); } $locker = $this->getMockBuilder('Composer\\Package\\Locker')->disableOriginalConstructor()->getMock(); $installationManager = new InstallationManagerMock(); $eventDispatcher = $this->getMockBuilder('Composer\\Script\\EventDispatcher')->disableOriginalConstructor()->getMock(); $autoloadGenerator = $this->getMock('Composer\\Autoload\\AutoloadGenerator'); $installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator); $result = $installer->run(); $this->assertTrue($result); $expectedInstalled = isset($options['install']) ? $options['install'] : array(); $expectedUpdated = isset($options['update']) ? $options['update'] : array(); $expectedUninstalled = isset($options['uninstall']) ? $options['uninstall'] : array(); $installed = $installationManager->getInstalledPackages(); $this->assertSame($expectedInstalled, $installed); $updated = $installationManager->getUpdatedPackages(); $this->assertSame($expectedUpdated, $updated); $uninstalled = $installationManager->getUninstalledPackages(); $this->assertSame($expectedUninstalled, $uninstalled); }
public function load(array $config, $class = 'Composer\\Package\\RootPackage') { if (!isset($config['name'])) { $config['name'] = '__root__'; } $autoVersioned = false; if (!isset($config['version'])) { // override with env var if available if (getenv('COMPOSER_ROOT_VERSION')) { $version = getenv('COMPOSER_ROOT_VERSION'); } else { $version = $this->versionGuesser->guessVersion($config, getcwd()); } if (!$version) { $version = '1.0.0'; $autoVersioned = true; } $config['version'] = $version; } $realPackage = $package = parent::load($config, $class); if ($realPackage instanceof AliasPackage) { $realPackage = $package->getAliasOf(); } if ($autoVersioned) { $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)'); } if (isset($config['minimum-stability'])) { $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); } $aliases = array(); $stabilityFlags = array(); $references = array(); foreach (array('require', 'require-dev') as $linkType) { if (isset($config[$linkType])) { $linkInfo = BasePackage::$supportedLinkTypes[$linkType]; $method = 'get' . ucfirst($linkInfo['method']); $links = array(); foreach ($realPackage->{$method}() as $link) { $links[$link->getTarget()] = $link->getConstraint()->getPrettyString(); } $aliases = $this->extractAliases($links, $aliases); $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability()); $references = $this->extractReferences($links, $references); } } $realPackage->setAliases($aliases); $realPackage->setStabilityFlags($stabilityFlags); $realPackage->setReferences($references); if (isset($config['prefer-stable'])) { $realPackage->setPreferStable((bool) $config['prefer-stable']); } $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager); foreach ($repos as $repo) { $this->manager->addRepository($repo); } $realPackage->setRepositories($this->config->getRepositories()); return $package; }
/** * Adds asset registry repositories. * * @param RepositoryManager $rm * @param VcsPackageFilter $filter * @param array $extra */ public static function addRegistryRepositories(RepositoryManager $rm, VcsPackageFilter $filter, array $extra) { $opts = array_key_exists('asset-registry-options', $extra) ? $extra['asset-registry-options'] : array(); foreach (Assets::getRegistries() as $assetType => $registryClass) { $config = array('repository-manager' => $rm, 'vcs-package-filter' => $filter, 'asset-options' => static::createAssetOptions($opts, $assetType)); $rm->setRepositoryClass($assetType, $registryClass); $rm->addRepository($rm->createRepository($assetType, $config)); } }
public function testPrepend() { $rm = new RepositoryManager($this->getMock('Composer\\IO\\IOInterface'), $this->getMock('Composer\\Config'), $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock()); $repository1 = $this->getMock('Composer\\Repository\\RepositoryInterface'); $repository2 = $this->getMock('Composer\\Repository\\RepositoryInterface'); $rm->addRepository($repository1); $rm->prependRepository($repository2); $this->assertEquals(array($repository2, $repository1), $rm->getRepositories()); }
/** * Add repository instance. * * @param IOInterface $io The IO instance * @param RepositoryManager $rm The repository mamanger * @param array $repos The list of already repository added (passed by reference) * @param string $name The name of the new repository * @param RepositoryInterface $repo The repository instance * @param Pool|null $pool The pool */ public static function addRepositoryInstance(IOInterface $io, RepositoryManager $rm, array &$repos, $name, RepositoryInterface $repo, Pool $pool = null) { if (!isset($repos[$name])) { static::writeAddRepository($io, $name); $repos[$name] = $repo; $rm->addRepository($repo); if (null !== $pool) { $pool->addRepository($repo); } } }
public function testOverridingVcsRepositoryConfig() { $name = $this->getType() . '-asset/foobar'; $rfs = $this->replaceRegistryRfsByMock(); $rfs->expects($this->any())->method('getContents')->will($this->returnValue(json_encode($this->getMockPackageForVcsConfig()))); $repo = $this->getMockBuilder('Fxp\\Composer\\AssetPlugin\\Repository\\AssetVcsRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->any())->method('getComposerPackageName')->will($this->returnValue($name)); /* @var AssetVcsRepository $repo */ $this->rm->addRepository($repo); $this->assertCount(0, $this->registry->whatProvides($this->pool, $name)); }
/** * @param RepositoryManager $rm The repository mamanger * @param array $repos The list of already repository added (passed by reference) * @param string $name The name of the new repository * @param array $repoConfig The config of the new repository * @param Pool|null $pool The pool */ public static function addRepository(RepositoryManager $rm, array &$repos, $name, array $repoConfig, Pool $pool = null) { if (!isset($repos[$name])) { $repo = $rm->createRepository($repoConfig['type'], $repoConfig); $repos[$name] = $repo; $rm->addRepository($repo); if (null !== $pool) { $pool->addRepository($repo); } } }
public function __construct() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $this->config = new Config(); $this->repositoryManager = $rm = new RepositoryManager(new NullIO(), $this->config); $rm->setRepositoryClass('composer', 'Composer\\Repository\\ComposerRepository'); $rm->setRepositoryClass('vcs', 'Composer\\Repository\\VcsRepository'); $rm->setRepositoryClass('package', 'Composer\\Repository\\PackageRepository'); $rm->setRepositoryClass('pear', 'Composer\\Repository\\PearRepository'); $rm->setRepositoryClass('git', 'Composer\\Repository\\VcsRepository'); $rm->setRepositoryClass('svn', 'Composer\\Repository\\VcsRepository'); $rm->setRepositoryClass('perforce', 'Composer\\Repository\\VcsRepository'); $rm->setRepositoryClass('hg', 'Composer\\Repository\\VcsRepository'); $rm->setRepositoryClass('artifact', 'Composer\\Repository\\ArtifactRepository'); $home = $this->getHomeDir(); $cache = $this->getCacheDir($home); $this->config->merge(array('config' => array('home' => $home, 'cache-dir' => $cache))); foreach ($this->config->getRepositories() as $index => $repo) { if (!is_array($repo)) { throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') should be an array, ' . gettype($repo) . ' given'); } if (!isset($repo['type'])) { throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined'); } $name = is_int($index) && isset($repo['url']) ? preg_replace('{^https?://}i', '', $repo['url']) : $index; while (isset($repos[$name])) { $name .= '2'; } $repo_object = $rm->createRepository($repo['type'], $repo); $rm->addRepository($repo_object); } }
protected function addPackagistRepository(RepositoryManager $rm) { $rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org'))); }
/** * @param array $config package data * @param string $class FQCN to be instantiated * @param string $cwd cwd of the root package to be used to guess the version if it is not provided * @return RootPackageInterface */ public function load(array $config, $class = 'Composer\\Package\\RootPackage', $cwd = null) { if (!isset($config['name'])) { $config['name'] = '__root__'; } $autoVersioned = false; if (!isset($config['version'])) { // override with env var if available if (getenv('COMPOSER_ROOT_VERSION')) { $version = getenv('COMPOSER_ROOT_VERSION'); $commit = null; } else { $versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd()); $version = $versionData['version']; $commit = $versionData['commit']; } if (!$version) { $version = '1.0.0'; $autoVersioned = true; } $config['version'] = $version; if ($commit) { $config['source'] = array('type' => '', 'url' => '', 'reference' => $commit); $config['dist'] = array('type' => '', 'url' => '', 'reference' => $commit); } } $realPackage = $package = parent::load($config, $class); if ($realPackage instanceof AliasPackage) { $realPackage = $package->getAliasOf(); } if ($autoVersioned) { $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)'); } if (isset($config['minimum-stability'])) { $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); } $aliases = array(); $stabilityFlags = array(); $references = array(); foreach (array('require', 'require-dev') as $linkType) { if (isset($config[$linkType])) { $linkInfo = BasePackage::$supportedLinkTypes[$linkType]; $method = 'get' . ucfirst($linkInfo['method']); $links = array(); foreach ($realPackage->{$method}() as $link) { $links[$link->getTarget()] = $link->getConstraint()->getPrettyString(); } $aliases = $this->extractAliases($links, $aliases); $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability()); $references = $this->extractReferences($links, $references); } } if (isset($links[$config['name']])) { throw new \InvalidArgumentException(sprintf('Root package \'%s\' cannot require itself in its composer.json' . PHP_EOL . 'Did you accidentally name your root package after an external package?', $config['name'])); } $realPackage->setAliases($aliases); $realPackage->setStabilityFlags($stabilityFlags); $realPackage->setReferences($references); if (isset($config['prefer-stable'])) { $realPackage->setPreferStable((bool) $config['prefer-stable']); } if (isset($config['config'])) { $realPackage->setConfig($config['config']); } $repos = RepositoryFactory::defaultRepos(null, $this->config, $this->manager); foreach ($repos as $repo) { $this->manager->addRepository($repo); } $realPackage->setRepositories($this->config->getRepositories()); return $package; }