public function testPrettyString() { $repo = new ArrayRepository(); $repo->addPackage($p1 = $this->getPackage('foo', '2.1')); $repo->addPackage($p2 = $this->getPackage('baz', '1.1')); $this->pool->addRepository($repo); $rule = new Rule(array($p1->getId(), -$p2->getId()), 'job1', null); $this->assertEquals('(don\'t install baz 1.1|install foo 2.1)', $rule->getPrettyString($this->pool)); }
public function testToString() { $repo = new ArrayRepository(); $repo->addPackage($p1 = $this->getPackage('foo', '2.1')); $repo->addPackage($p2 = $this->getPackage('baz', '1.1')); $this->pool->addRepository($repo); $rule = new Rule($this->pool, array($p1->getId(), -$p2->getId()), 'job1', null); $this->assertEquals('(-baz-1.1.0.0|+foo-2.1.0.0)', $rule->__toString()); }
public function testAutomaticallyAddAliasedPackage() { $repo = new ArrayRepository(); $package = $this->getPackage('foo', '1'); $alias = $this->getAliasPackage($package, '2'); $repo->addPackage($alias); $this->assertEquals(2, count($repo)); $this->assertTrue($repo->hasPackage($this->getPackage('foo', '1'))); $this->assertTrue($repo->hasPackage($this->getPackage('foo', '2'))); }
public function testSolverInstallSamePackageFromDifferentRepositories() { $repo1 = new ArrayRepository(); $repo2 = new ArrayRepository(); $repo1->addPackage($foo1 = $this->getPackage('foo', '1')); $repo2->addPackage($foo2 = $this->getPackage('foo', '1')); $this->pool->addRepository($this->repoInstalled); $this->pool->addRepository($repo1); $this->pool->addRepository($repo2); $this->request->install('foo'); $this->checkSolverResult(array(array('job' => 'install', 'package' => $foo1))); }
public function testRequestInstallSamePackageFromDifferentRepositories() { $repo1 = new ArrayRepository(); $repo2 = new ArrayRepository(); $foo1 = $this->getPackage('foo', '1'); $foo2 = $this->getPackage('foo', '1'); $repo1->addPackage($foo1); $repo2->addPackage($foo2); $request = new Request(); $request->install('foo', $constraint = $this->getVersionConstraint('=', '1')); $this->assertEquals(array(array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint, 'fixed' => false)), $request->getJobs()); }
public function testGetMaxId() { $pool = new Pool(); $repository = new ArrayRepository(); $firstPackage = $this->getPackage('foo', '1'); $secondPackage = $this->getPackage('foo1', '1'); $this->assertEquals(0, $pool->getMaxId()); $repository->addPackage($firstPackage); $repository->addPackage($secondPackage); $pool->addRepository($repository); $this->assertEquals(2, $pool->getMaxId()); }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new MemoryPackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); foreach (get_loaded_extensions() as $name) { if (in_array($name, array('standard', 'Core'))) { continue; } $reflExt = new \ReflectionExtension($name); try { $prettyVersion = $reflExt->getVersion(); $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = '0'; $version = $versionParser->normalize($prettyVersion); } $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); parent::addPackage($ext); } }
protected function initialize() { parent::initialize(); $this->io->write('Initializing PEAR repository ' . $this->url); $this->initializeChannel(); $this->io->write('Packages names will be prefixed with: pear-' . $this->channel . '/'); // try to load as a composer repo try { $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io)); $packages = $json->read(); if ($this->io->isVerbose()) { $this->io->write('Repository is Composer-compatible, loading via packages.json instead of PEAR protocol'); } $loader = new ArrayLoader(); foreach ($packages as $data) { foreach ($data['versions'] as $rev) { if (strpos($rev['name'], 'pear-' . $this->channel) !== 0) { $rev['name'] = 'pear-' . $this->channel . '/' . $rev['name']; } $this->addPackage($loader->load($rev)); if ($this->io->isVerbose()) { $this->io->write('Loaded ' . $rev['name'] . ' ' . $rev['version']); } } } return; } catch (\Exception $e) { } $this->fetchFromServer(); }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); if (!$this->file->exists()) { return; } $packages = $this->file->read(); if (!is_array($packages)) { throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository'); } $loader = new ArrayLoader(); foreach ($packages as $packageData) { $package = $loader->load($packageData); // package was installed as alias, so we only add the alias if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) { $alias = $packageData['installed-as-alias']; $package->setAlias($alias); $package->setPrettyAlias($alias); $package->setInstalledAsAlias(true); $this->addPackage($this->createAliasPackage($package, $alias, $alias)); } else { // only add regular package - if it's not an installed repo the alias will be created on the fly $this->addPackage($package); } } }
protected function initialize() { parent::initialize(); if (!extension_loaded('openssl') && 'https' === substr($this->url, 0, 5)) { throw new \RuntimeException('You must enable the openssl extension in your php.ini to load information from ' . $this->url); } try { $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io)); $data = $json->read(); if (!empty($data['notify'])) { if ('/' === $data['notify'][0]) { $this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url); } else { $this->notifyUrl = $data['notify']; } } $this->cache->write('packages.json', json_encode($data)); } catch (\Exception $e) { if ($contents = $this->cache->read('packages.json')) { $this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>'); $data = json_decode($contents, true); } else { throw $e; } } $loader = new ArrayLoader(); $this->loadRepository($loader, $data); }
public function testRequestInstallAndRemove() { $pool = new Pool(); $repo = new ArrayRepository(); $foo = $this->getPackage('foo', '1'); $bar = $this->getPackage('bar', '1'); $foobar = $this->getPackage('foobar', '1'); $repo->addPackage($foo); $repo->addPackage($bar); $repo->addPackage($foobar); $pool->addRepository($repo); $request = new Request($pool); $request->install('foo'); $request->install('bar'); $request->remove('foobar'); $this->assertEquals(array(array('packages' => array($foo), 'cmd' => 'install', 'packageName' => 'foo'), array('packages' => array($bar), 'cmd' => 'install', 'packageName' => 'bar'), array('packages' => array($foobar), 'cmd' => 'remove', 'packageName' => 'foobar')), $request->getJobs()); }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); $loader = new ArrayLoader(); foreach ($this->config as $package) { $package = $loader->load($package); $this->addPackage($package); } }
protected function initialize() { parent::initialize(); set_error_handler(function ($severity, $message, $file, $line) { throw new \ErrorException($message, $severity, $severity, $file, $line); }); $this->streamContext = StreamContextFactory::getContext(); $this->fetchFromServer(); restore_error_handler(); }
/** * @return array */ public function dataGetPackages() { $emptyRepo = new ArrayRepository(); $vendorRepo = new ArrayRepository(); $vendorRepo2 = new ArrayRepository(); $package = new Package('vendor/name', '1.0.0.0', '1.0'); $package2 = new Package('vendor2/name', '1.0.0.0', '1.0'); $package3 = new Package('vendor2/name2', '1.0.0.0', '1.0'); $vendorRepo->addPackage($package); $vendorRepo2->addPackage($package2); $vendorRepo2->addPackage($package3); $data = []; $data['empty repository'] = [[], [], $emptyRepo]; $data['empty repository with filter'] = [[], ['vendor/name'], $emptyRepo]; $data['repository with one package'] = [[$package], [], $vendorRepo]; $data['repository with one package and filter'] = [[], ['othervendor/othername'], $vendorRepo]; $data['repository with two packages'] = [[$package2, $package3], [], $vendorRepo2]; $data['repository with two packages and filter'] = [[$package2], ['vendor2/name'], $vendorRepo2]; return $data; }
public function dataGetPackages() { $emptyRepo = new ArrayRepository(); $vendorRepo = new ArrayRepository(); $vendorRepo2 = new ArrayRepository(); $package = new Package('vendor/name', '1.0.0.0', '1.0'); $package2 = new Package('vendor2/name', '1.0.0.0', '1.0'); $package3 = new Package('vendor2/name2', '1.0.0.0', '1.0'); $vendorRepo->addPackage($package); $vendorRepo2->addPackage($package2); $vendorRepo2->addPackage($package3); $data = array(); $data['empty repository'] = array(array(), array(), $emptyRepo); $data['empty repository with filter'] = array(array(), array('vendor/name'), $emptyRepo); $data['repository with one package'] = array(array($package), array(), $vendorRepo); $data['repository with one package and filter'] = array(array(), array('othervendor/othername'), $vendorRepo); $data['repository with two packages'] = array(array($package2, $package3), array(), $vendorRepo2); $data['repository with two packages and filter'] = array(array($package2), array('vendor2/name'), $vendorRepo2); return $data; }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); if (!is_numeric(key($this->config))) { $this->config = array($this->config); } $loader = new ArrayLoader(); foreach ($this->config as $package) { $package = $loader->load($package); $this->addPackage($package); } }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); $loader = new ValidatingArrayLoader(new ArrayLoader(null, true), false); foreach ($this->config as $package) { try { $package = $loader->load($package); } catch (\Exception $e) { throw new InvalidRepositoryException('A repository of type "package" contains an invalid package definition: ' . $e->getMessage() . "\n\nInvalid package definition:\n" . json_encode($package)); } $this->addPackage($package); } }
public function testSearchWithPackageType() { $repo = new ArrayRepository(); $repo->addPackage($this->getPackage('foo', '1', 'Composer\\Package\\CompletePackage')); $repo->addPackage($this->getPackage('bar', '1', 'Composer\\Package\\CompletePackage')); $package = $this->getPackage('foobar', '1', 'Composer\\Package\\CompletePackage'); $package->setType('composer-plugin'); $repo->addPackage($package); $this->assertSame(array(array('name' => 'foo', 'description' => null)), $repo->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library')); $this->assertEmpty($repo->search('bar', RepositoryInterface::SEARCH_FULLTEXT, 'package')); $this->assertSame(array(array('name' => 'foobar', 'description' => null)), $repo->search('foo', 0, 'composer-plugin')); }
public static function Construct(IOInterface $io) { $repo = new ArrayRepository(); try { $web_folder = Locator::getWebFolderPath(); $version_file = $web_folder . '/intranet/setup/_init/version.txt'; if (!file_exists($version_file)) { throw new \Exception("No version.txt for core found - assuming framework is not installed"); } $version_data = file($version_file); $core_version = $version_data[1]; $normalizer = new VersionParser(); $core_version_normalized = $normalizer->normalize($core_version); $io->write("Detected core version {$core_version} ({$core_version_normalized})"); $core_package = new Package(FrameworkInstallerV8::PACKAGE_NAME, $core_version_normalized, $core_version); $repo->addPackage($core_package); } catch (\Exception $e) { $io->write($e->getMessage()); // if can't determine location of 'web' folder, not adding the core package therefore letting // composer install it } return $repo; }
public function getLockedRepository($withDevReqs = false) { $lockData = $this->getLockData(); $packages = new ArrayRepository(); $lockedPackages = $lockData['packages']; if ($withDevReqs) { if (isset($lockData['packages-dev'])) { $lockedPackages = array_merge($lockedPackages, $lockData['packages-dev']); } else { throw new \RuntimeException('The lock file does not contain require-dev information, run install with the --no-dev option or run update to install those packages.'); } } if (empty($lockedPackages)) { return $packages; } if (isset($lockedPackages[0]['name'])) { foreach ($lockedPackages as $info) { $packages->addPackage($this->loader->load($info)); } return $packages; } throw new \RuntimeException('Your composer.lock was created before 2012-09-15, and is not supported anymore. Run "composer update" to generate a new one.'); }
public function testSelectLowest() { $policy = new DefaultPolicy(false, true); $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); $this->pool->addRepository($this->repo); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA1->getId()); $selected = $policy->selectPreferredPackages($this->pool, array(), $literals); $this->assertSame($expected, $selected); }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); if (!$this->file->exists()) { return; } $packages = $this->file->read(); if (!is_array($packages)) { throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository'); } $loader = new ArrayLoader(); foreach ($packages as $package) { $this->addPackage($loader->load($package)); } }
protected function initialize() { parent::initialize(); $json = new JsonFile($this->url . '/packages.json'); $packages = $json->read(); if (!$packages) { throw new \UnexpectedValueException('Could not parse package list from the ' . $this->url . ' repository'); } $loader = new ArrayLoader(); foreach ($packages as $data) { foreach ($data['versions'] as $rev) { $this->addPackage($loader->load($rev)); } } }
protected function initialize() { parent::initialize(); $this->io->writeError('Initializing PEAR repository ' . $this->url); $reader = new ChannelReader($this->rfs); try { $channelInfo = $reader->read($this->url); } catch (\Exception $e) { $this->io->writeError('<warning>PEAR repository from ' . $this->url . ' could not be loaded. ' . $e->getMessage() . '</warning>'); return; } $packages = $this->buildComposerPackages($channelInfo, $this->versionParser); foreach ($packages as $package) { $this->addPackage($package); } }
protected function initialize() { parent::initialize(); $loader = new ArrayLoader(null, true); $directories = glob($this->directory . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT); foreach ($directories as $directory) { if (!file_exists($directory . DIRECTORY_SEPARATOR . 'composer.json')) { continue; } $jsonFile = new JsonFile($directory . DIRECTORY_SEPARATOR . 'composer.json'); $packageData = $jsonFile->read(); $packageData['version'] = '1.0'; $package = $loader->load($packageData); $this->addPackage($package); } }
/** * @expectedException \RuntimeException * @expectedExceptionMessage We cannot retrieve information on magento/product-community-edition. */ public function testGetPackageVersionsFailed() { $communityPackage = $this->getMock('\\Composer\\Package\\Package', [], [], '', false); $enterprisePackage = $this->getMock('\\Composer\\Package\\Package', [], [], '', false); $communityPackage->expects($this->once())->method('getName')->willReturn('magento/product-community-edition'); $enterprisePackage->expects($this->once())->method('getName')->willReturn('magento/product-enterprise-edition'); $this->composerInformation->expects($this->any())->method('isSystemPackage')->willReturn(true); $this->composerInformation->expects($this->once())->method('isPackageInComposerJson')->willReturn(true); $this->repository->expects($this->once())->method('getPackages')->willReturn([$communityPackage, $enterprisePackage]); $this->locker->expects($this->once())->method('getLockedRepository')->willReturn($this->repository); $this->composer->expects($this->once())->method('getLocker')->willReturn($this->locker); $this->magentoComposerApp->expects($this->once())->method('createComposer')->willReturn($this->composer); $this->composerAppFactory->expects($this->once())->method('create')->willReturn($this->magentoComposerApp); $this->composerAppFactory->expects($this->once())->method('createInfoCommand')->willReturn($this->infoCommand); $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation); $this->infoCommand->expects($this->once())->method('run')->with('magento/product-community-edition')->willReturn(false); $this->systemPackage->getPackageVersions(); }
public function testFindPackagesByName() { $repo = new ArrayRepository(); $repo->addPackage($this->getPackage('foo', '1')); $repo->addPackage($this->getPackage('bar', '2')); $repo->addPackage($this->getPackage('bar', '3')); $foo = $repo->findPackagesByName('foo'); $this->assertCount(1, $foo); $this->assertEquals('foo', $foo[0]->getName()); $bar = $repo->findPackagesByName('bar'); $this->assertCount(2, $bar); $this->assertEquals('bar', $bar[0]->getName()); }
/** * Initializes repository (reads file, or remote address). */ protected function initialize() { parent::initialize(); if (!$this->file->exists()) { return; } try { $packages = $this->file->read(); if (!is_array($packages)) { throw new \UnexpectedValueException('Could not parse package list from the repository'); } } catch (\Exception $e) { throw new InvalidRepositoryException('Invalid repository data in ' . $this->file->getPath() . ', packages could not be loaded: [' . get_class($e) . '] ' . $e->getMessage()); } $loader = new ArrayLoader(); foreach ($packages as $packageData) { $package = $loader->load($packageData); $this->addPackage($package); } }
protected function initialize() { parent::initialize(); try { $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io)); $data = $json->read(); if (!empty($data['notify'])) { $this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url); } $this->cache->write('packages.json', json_encode($data)); } catch (\Exception $e) { if ($contents = $this->cache->read('packages.json')) { $this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>'); $data = json_decode($contents, true); } else { throw $e; } } $loader = new ArrayLoader(); $this->loadRepository($loader, $data); }
public function testPrettyString() { $repo = new ArrayRepository(); $repo->addPackage($p = $this->getPackage('foo', '2.1')); $this->pool->addRepository($repo); $ruleSet = new RuleSet(); $literal = $p->getId(); $rule = new Rule(array($literal), Rule::RULE_JOB_INSTALL, null); $ruleSet->add($rule, RuleSet::TYPE_JOB); $this->assertContains('JOB : Install command rule (install foo 2.1)', $ruleSet->getPrettyString($this->pool)); }