Esempio n. 1
0
 public function testRun()
 {
     $app = $this->getApp();
     $testPackage = new CompletePackage('test', '1.0.1', '1.0');
     $testPackage->setDescription('An extension');
     $testPackage->setType('bolt-extension');
     $runner = $this->getMockBuilder(PackageManager::class)->setMethods(['showPackage'])->setConstructorArgs([$app])->getMock();
     $runner->expects($this->any())->method('showPackage')->will($this->returnValue(['test' => ['package' => $testPackage]]));
     $app['extend.manager'] = $runner;
     $command = new Extensions($app);
     $tester = new CommandTester($command);
     $tester->execute([]);
     $result = $tester->getDisplay();
     $this->assertRegExp('/Name.*Version/', $result);
     $this->assertRegExp('/test.*1.0/', $result);
 }
Esempio n. 2
0
 public function testRun()
 {
     $app = $this->getApp();
     $testPackage = new CompletePackage('test', '1.0.1', '1.0');
     $testPackage->setDescription('An extension');
     $testPackage->setType('bolt-extension');
     $runner = $this->getMock("Bolt\\Composer\\PackageManager", array('showPackage'), array($app));
     $runner->expects($this->any())->method('showPackage')->will($this->returnValue(array('test' => array('package' => $testPackage))));
     $app['extend.manager'] = $runner;
     $command = new Extensions($app);
     $command->setHelperSet(new HelperSet(array(new TableHelper())));
     $tester = new CommandTester($command);
     $tester->execute(array());
     $result = $tester->getDisplay();
     $this->assertRegexp('/Name.*Version/', $result);
     $this->assertRegexp('/test.*1.0/', $result);
 }
 public function testShouldCreatePackages()
 {
     $reader = $this->getMockBuilder('\\Composer\\Repository\\PearRepository')->disableOriginalConstructor()->getMock();
     $ref = new \ReflectionMethod($reader, 'buildComposerPackages');
     $ref->setAccessible(true);
     $channelInfo = new ChannelInfo('test.loc', 'test', array(new PackageInfo('test.loc', 'sample', 'license', 'shortDescription', 'description', array('1.0.0.1' => new ReleaseInfo('stable', new DependencyInfo(array(new DependencyConstraint('required', '> 5.2.0.0', 'php', ''), new DependencyConstraint('conflicts', '== 2.5.6.0', 'pear.php.net', 'broken')), array('*' => array(new DependencyConstraint('optional', '*', 'ext', 'xml')))))))));
     $packages = $ref->invoke($reader, $channelInfo, new VersionParser());
     $expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1', '1.0.0.1');
     $expectedPackage->setType('pear-library');
     $expectedPackage->setDistType('file');
     $expectedPackage->setDescription('description');
     $expectedPackage->setDistUrl("http://test.loc/get/sample-1.0.0.1.tgz");
     $expectedPackage->setAutoload(array('classmap' => array('')));
     $expectedPackage->setIncludePaths(array('/'));
     $expectedPackage->setRequires(array(new Link('pear-test.loc/sample', 'php', $this->createConstraint('>', '5.2.0.0'), 'required', '> 5.2.0.0')));
     $expectedPackage->setConflicts(array(new Link('pear-test.loc/sample', 'pear-pear.php.net/broken', $this->createConstraint('==', '2.5.6.0'), 'conflicts', '== 2.5.6.0')));
     $expectedPackage->setSuggests(array('*-ext-xml' => '*'));
     $expectedPackage->setReplaces(array(new Link('pear-test.loc/sample', 'pear-test/sample', new VersionConstraint('==', '1.0.0.1'), 'replaces', '== 1.0.0.1')));
     $this->assertCount(1, $packages);
     $this->assertEquals($expectedPackage, $packages[0], 0, 1);
 }
Esempio n. 4
0
 /**
  * Builds CompletePackages from PEAR package definition data.
  *
  * @param  ChannelInfo     $channelInfo
  * @param  VersionParser   $versionParser
  * @return CompletePackage
  */
 private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser)
 {
     $result = array();
     foreach ($channelInfo->getPackages() as $packageDefinition) {
         foreach ($packageDefinition->getReleases() as $version => $releaseInfo) {
             try {
                 $normalizedVersion = $versionParser->normalize($version);
             } catch (\UnexpectedValueException $e) {
                 if ($this->io->isVerbose()) {
                     $this->io->writeError('Could not load ' . $packageDefinition->getPackageName() . ' ' . $version . ': ' . $e->getMessage());
                 }
                 continue;
             }
             $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName());
             // distribution url must be read from /r/{packageName}/{version}.xml::/r/g:text()
             // but this location is 'de-facto' standard
             $urlBits = parse_url($this->url);
             $scheme = isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl') ? 'https' : 'http';
             $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz";
             $requires = array();
             $suggests = array();
             $conflicts = array();
             $replaces = array();
             // alias package only when its channel matches repository channel,
             // cause we've know only repository channel alias
             if ($channelInfo->getName() == $packageDefinition->getChannelName()) {
                 $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName());
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             // alias package with user-specified prefix. it makes private pear channels looks like composer's.
             if (!empty($this->vendorAlias) && ($this->vendorAlias != 'pear-' . $channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())) {
                 $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}";
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) {
                 $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                 $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint());
                 $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint());
                 switch ($dependencyConstraint->getType()) {
                     case 'required':
                         $requires[] = $link;
                         break;
                     case 'conflicts':
                         $conflicts[] = $link;
                         break;
                     case 'replaces':
                         $replaces[] = $link;
                         break;
                 }
             }
             foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) {
                 foreach ($dependencyConstraints as $dependencyConstraint) {
                     $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                     $suggests[$group . '-' . $dependencyPackageName] = $dependencyConstraint->getConstraint();
                 }
             }
             $package = new CompletePackage($composerPackageName, $normalizedVersion, $version);
             $package->setType('pear-library');
             $package->setDescription($packageDefinition->getDescription());
             $package->setLicense(array($packageDefinition->getLicense()));
             $package->setDistType('file');
             $package->setDistUrl($distUrl);
             $package->setAutoload(array('classmap' => array('')));
             $package->setIncludePaths(array('/'));
             $package->setRequires($requires);
             $package->setConflicts($conflicts);
             $package->setSuggests($suggests);
             $package->setReplaces($replaces);
             $result[] = $package;
         }
     }
     return $result;
 }
Esempio n. 5
0
File: Plugin.php Progetto: Jobu/core
 /**
  * Inject the currently installed contao/core as meta package.
  *
  * @return void
  *
  * @throws ConstantsNotFoundException When the root path could not be determined.
  */
 public function injectContaoCore()
 {
     $roots = Environment::findContaoRoots($this->composer->getPackage());
     if (0 === count($roots)) {
         throw new ConstantsNotFoundException('Could not find contao root path and therefore no constants.php');
     }
     // Duplicate installation, remove from vendor folder
     $removeVendor = count($roots) > 1 && isset($roots['vendor']);
     $root = $this->getContaoRoot($this->composer->getPackage());
     $repositoryManager = $this->composer->getRepositoryManager();
     $localRepository = $repositoryManager->getLocalRepository();
     $versionParser = new VersionParser();
     $prettyVersion = $this->prepareContaoVersion($this->getContaoVersion(), $this->getContaoBuild());
     $version = $versionParser->normalize($prettyVersion);
     // @codingStandardsIgnoreStart
     // Sadly we can not add the bundles as provided packages, as the Pool cleans them up.
     // See also: https://github.com/composer/composer/blob/2d19cf/src/Composer/DependencyResolver/Pool.php#L174
     // The skipping in there ignores any provided packages, even from already installed ones, and therefore makes
     // this approach impossible.
     // We therefore register them all as meta packages in the local repository and require them in the same version
     // below then.
     // @codingStandardsIgnoreEnd
     $this->injectContaoBundles($localRepository, $version, $prettyVersion);
     /** @var PackageInterface $localPackage */
     foreach ($localRepository->getPackages() as $localPackage) {
         if ($localPackage->getName() === 'contao/core') {
             if ($removeVendor) {
                 $this->composer->getInstallationManager()->uninstall($localRepository, new UninstallOperation($localPackage));
             } elseif ($this->isNotMetaPackageOrHasSameVersion($localPackage, $version)) {
                 // stop if the contao package is required somehow and must not be injected or
                 // if the virtual contao package is already injected
                 return;
             }
             // Remove package otherwise.
             $localRepository->removePackage($localPackage);
             break;
         }
     }
     $contaoCore = new CompletePackage('contao/core', $version, $prettyVersion);
     $contaoCore->setType('metapackage');
     $this->injectSwiftMailer($root, $contaoCore);
     $clientLink = new Link('contao/core', 'contao-community-alliance/composer-client', $this->createEmptyConstraint('~0.14'), 'requires', '~0.14');
     $requires = array('contao-community-alliance/composer-client' => $clientLink);
     // Add the bundles now.
     foreach (Environment::$bundleNames as $bundleName) {
         if ($package = $localRepository->findPackage($bundleName, '*')) {
             $requires[$bundleName] = new Link('contao/core', $bundleName, $this->createEmptyConstraint($package->getVersion()), 'requires', $package->getVersion());
         }
     }
     $contaoCore->setRequires($requires);
     $localRepository->addPackage($contaoCore);
 }
Esempio n. 6
0
 private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser)
 {
     $result = array();
     foreach ($channelInfo->getPackages() as $packageDefinition) {
         foreach ($packageDefinition->getReleases() as $version => $releaseInfo) {
             try {
                 $normalizedVersion = $versionParser->normalize($version);
             } catch (\UnexpectedValueException $e) {
                 if ($this->io->isVerbose()) {
                     $this->io->write('Could not load ' . $packageDefinition->getPackageName() . ' ' . $version . ': ' . $e->getMessage());
                 }
                 continue;
             }
             $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName());
             $urlBits = parse_url($this->url);
             $scheme = isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl') ? 'https' : 'http';
             $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz";
             $requires = array();
             $suggests = array();
             $conflicts = array();
             $replaces = array();
             if ($channelInfo->getName() == $packageDefinition->getChannelName()) {
                 $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName());
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             if (!empty($this->vendorAlias) && ($this->vendorAlias != 'pear-' . $channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())) {
                 $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}";
                 $aliasConstraint = new VersionConstraint('==', $normalizedVersion);
                 $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
             }
             foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) {
                 $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                 $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint());
                 $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint());
                 switch ($dependencyConstraint->getType()) {
                     case 'required':
                         $requires[] = $link;
                         break;
                     case 'conflicts':
                         $conflicts[] = $link;
                         break;
                     case 'replaces':
                         $replaces[] = $link;
                         break;
                 }
             }
             foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) {
                 foreach ($dependencyConstraints as $dependencyConstraint) {
                     $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
                     $suggests[$group . '-' . $dependencyPackageName] = $dependencyConstraint->getConstraint();
                 }
             }
             $package = new CompletePackage($composerPackageName, $normalizedVersion, $version);
             $package->setType('pear-library');
             $package->setDescription($packageDefinition->getDescription());
             $package->setDistType('file');
             $package->setDistUrl($distUrl);
             $package->setAutoload(array('classmap' => array('')));
             $package->setIncludePaths(array('/'));
             $package->setRequires($requires);
             $package->setConflicts($conflicts);
             $package->setSuggests($suggests);
             $package->setReplaces($replaces);
             $result[] = $package;
         }
     }
     return $result;
 }
 /**
  * Test the conversion of a complete repository.
  *
  * @return void
  */
 public function testConvertRepositoryToArrayOnlyRequired()
 {
     $repository = new ArrayRepository([$package1 = new CompletePackage('test/dependency1', '1.0.0.0', '1.0.0.0'), $package2 = new CompletePackage('test/non-dependency2', '2.0.0.0', '2.0.0.0')]);
     $package1->setType('project');
     $package1->setLicense(['LGPL-3']);
     $package2->setType('project');
     $package2->setLicense(['GPL-3']);
     $converter = new PackageConverter($rootPackage = new RootPackage('root/package', 'dev-master', 'dev-master'));
     $rootPackage->setRequires(['test/dependency1' => new Link('root/package', 'test/dependency1', new Constraint('<', '2.0'))]);
     $converted = $converter->convertRepositoryToArray($repository, true);
     $this->assertEquals(['test\\/dependency1'], $converted->getEntries('/'));
     $this->assertEquals(['test\\/dependency1/name', 'test\\/dependency1/version', 'test\\/dependency1/constraint', 'test\\/dependency1/type', 'test\\/dependency1/locked', 'test\\/dependency1/license', 'test\\/dependency1/abandoned'], $converted->getEntries('/test\\/dependency1'));
     $this->assertEquals($package1->getName(), $converted->get('test\\/dependency1/name'));
     $this->assertEquals($package1->getPrettyVersion(), $converted->get('test\\/dependency1/version'));
     $this->assertEquals($converted->get('test\\/dependency1/constraint'), '< 2.0');
     $this->assertEquals($package1->getType(), $converted->get('test\\/dependency1/type'));
     $this->assertFalse($converted->get('test\\/dependency1/locked'));
     $this->assertEquals($package1->getLicense(), $converted->get('test\\/dependency1/license'));
     $this->assertFalse($converted->get('test\\/dependency1/abandoned'));
 }