Ejemplo n.º 1
0
    /**
     * @dataProvider getRecommendedRequireVersionPackages
     */
    public function testFindRecommendedRequireVersion($prettyVersion, $isDev, $stability, $expectedVersion, $branchAlias = null)
    {
        $pool = $this->createMockPool();
        $versionSelector = new VersionSelector($pool);
        $versionParser = new VersionParser();

        $package = $this->getMock('\Composer\Package\PackageInterface');
        $package->expects($this->any())
            ->method('getPrettyVersion')
            ->will($this->returnValue($prettyVersion));
        $package->expects($this->any())
            ->method('getVersion')
            ->will($this->returnValue($versionParser->normalize($prettyVersion)));
        $package->expects($this->any())
            ->method('isDev')
            ->will($this->returnValue($isDev));
        $package->expects($this->any())
            ->method('getStability')
            ->will($this->returnValue($stability));

        $branchAlias = $branchAlias === null ? array() : array('branch-alias' => array($prettyVersion => $branchAlias));
        $package->expects($this->any())
            ->method('getExtra')
            ->will($this->returnValue($branchAlias));

        $recommended = $versionSelector->findRecommendedRequireVersion($package);

        // assert that the recommended version is what we expect
        $this->assertEquals($expectedVersion, $recommended);
    }
Ejemplo n.º 2
0
 /**
  * Given a package name, this determines the best version to use in the require key.
  *
  * This returns a version with the ~ operator prefixed when possible.
  *
  * @param string $name
  *
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 protected function findBestVersionForPackage($name)
 {
     $package = $this->versionSelector->findBestCandidate($name);
     if (!$package) {
         throw new \InvalidArgumentException(sprintf('Could not find package %s at any version for your minimum-stability (%s). Check the package spelling or your minimum-stability', $name, $this->getMinimumStability()));
     }
     return $this->versionSelector->findRecommendedRequireVersion($package);
 }
Ejemplo n.º 3
0
 /**
  * Given a package name, this determines the best version to use in the require key.
  *
  * This returns a version with the ~ operator prefixed when possible.
  *
  * @param  InputInterface            $input
  * @param  string                    $name
  * @param  string                    $phpVersion
  * @throws \InvalidArgumentException
  * @return string
  */
 private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion)
 {
     // find the latest version allowed in this pool
     $versionSelector = new VersionSelector($this->getPool($input));
     $package = $versionSelector->findBestCandidate($name, null, $phpVersion);
     if (!$package) {
         throw new \InvalidArgumentException(sprintf('Could not find package %s at any version for your minimum-stability (%s). Check the package spelling or your minimum-stability', $name, $this->getMinimumStability($input)));
     }
     return $versionSelector->findRecommendedRequireVersion($package);
 }
Ejemplo n.º 4
0
 /**
  * Given a package name, this determines the best version to use in the require key.
  *
  * This returns a version with the ~ operator prefixed when possible.
  *
  * @param string $name
  *
  * @throws \InvalidArgumentException
  *
  * @return array
  */
 public function findBestVersionForPackage($name)
 {
     // find the latest version allowed in this pool
     $versionSelector = new VersionSelector($this->getPool());
     $package = $versionSelector->findBestCandidate($name);
     if (!$package) {
         return null;
     }
     return array('name' => $name, 'version' => $package->getVersion(), 'prettyversion' => $package->getPrettyVersion(), 'package' => $package, 'requirever' => $versionSelector->findRecommendedRequireVersion($package));
 }
Ejemplo n.º 5
0
 /**
  * Given a concrete package, this returns a ~ constraint (in the future a ^ constraint)
  * that should be used, for example, in composer.json.
  * For example:
  *  * 1.2.1         -> ~1.2
  *  * 1.2           -> ~1.2
  *  * v3.2.1        -> ~3.2
  *  * 2.0-beta.1    -> ~2.0@beta
  *
  * @param string $vendor
  * @param string $package
  *
  * @return string
  */
 public function getDefaultConstraint($vendor, $package)
 {
     // Get versions.
     $versions = array_keys($this->getRawVersions($vendor, $package));
     // Get highest version.
     $highestVersion = reset($versions);
     $highestStability = $this->parser->parseStability($highestVersion);
     foreach ($versions as $version) {
         $nomalizedVersion = $this->parser->normalize($version);
         $nomalizedHighestVersion = $this->parser->normalize($highestVersion);
         if ($this->isMoreStable($version, $highestStability) || version_compare($nomalizedHighestVersion, $nomalizedVersion, '<')) {
             $highestVersion = $version;
             $highestStability = $this->parser->parseStability($version);
         }
     }
     // Let version selector format the constraint.
     $selector = new VersionSelector(new Pool());
     $package = new Package("{$vendor}/{$package}", $this->parser->normalize($highestVersion), $highestVersion);
     return $selector->findRecommendedRequireVersion($package);
 }
Ejemplo n.º 6
0
 /**
  * Given a package name, this determines the best version to use in the require key.
  *
  * This returns a version with the ^ operator prefixed when possible.
  *
  * @param string $packageName
  * @param string $targetPackageVersion
  * @param bool   $returnArray
  *
  * @throws \InvalidArgumentException
  *
  * @return PackageInterface|array
  */
 protected function findBestVersionForPackage($packageName, $targetPackageVersion = null, $returnArray = false)
 {
     $versionSelector = new VersionSelector($this->getPool());
     $package = $versionSelector->findBestCandidate($packageName, $targetPackageVersion, strtok(PHP_VERSION, '-'), $this->getComposer()->getPackage()->getStability());
     if (!$package) {
         if ($returnArray === false) {
             throw new \InvalidArgumentException(sprintf('Could not find package %s at any version for your minimum-stability (%s). Check the package spelling or your minimum-stability', $packageName, $this->getMinimumStability()));
         }
         return null;
     }
     if ($returnArray === false) {
         return $versionSelector->findRecommendedRequireVersion($package);
     }
     return ['name' => $packageName, 'version' => $package->getVersion(), 'prettyversion' => $package->getPrettyVersion(), 'package' => $package, 'requirever' => $versionSelector->findRecommendedRequireVersion($package)];
 }