/**
  * @dataProvider filterVersionsProvider()
  */
 public function testFilterVersions($constraint, $parentVersion, $input, $output)
 {
     $constraintObject = new ComposerConstraint($constraint, $parentVersion);
     $inputVersions = [];
     foreach ($input as $tag) {
         $inputVersions[$tag] = new Version($tag);
     }
     $result = $constraintObject->filterVersions($inputVersions);
     $this->assertEquals($output, array_keys($result), "Version constraint {$constraint} filters the given list");
 }
Esempio n. 2
0
 /**
  * Determine historic release plan from a past composer constraint
  *
  * @param LibraryRelease $newRelease
  * @param Version $historicVersion
  * @return ChangelogLibrary Changelog information for a library
  */
 protected function getChangelogLibrary(LibraryRelease $newRelease, Version $historicVersion)
 {
     // Build root release node
     $historicRelease = new ChangelogLibrary($newRelease, $historicVersion);
     // Check all dependencies from this past commit
     $pastComposer = null;
     foreach ($newRelease->getItems() as $childNewRelease) {
         // Lazy-load historic composer content as needed
         if (!isset($pastComposer)) {
             $pastComposer = $newRelease->getLibrary()->getHistoryComposerData($historicVersion);
         }
         // Check if this release has a historic tag.
         $childReleaseName = $childNewRelease->getLibrary()->getName();
         if (empty($pastComposer['require'][$childReleaseName])) {
             continue;
         }
         $historicConstraintName = $pastComposer['require'][$childReleaseName];
         // Get oldest existing tag that matches the given constraint as the "from" for changelog purposes.
         $historicConstraint = new ComposerConstraint($historicConstraintName, $historicVersion, $childReleaseName);
         $childVersions = $historicConstraint->filterVersions($childNewRelease->getLibrary()->getTags());
         // If "to" is stable, then filter out unstable "from"
         // E.g. prefer "3.4.0..3.4.1" over "3.4.0-rc1..3.4.1"
         if ($childNewRelease->getVersion()->isStable()) {
             $childVersions = Version::filter($childVersions, function (Version $nextTag) {
                 return $nextTag->isStable();
             });
         }
         // Get smallest matching version
         $childVersions = Version::sort($childVersions, Version::ASC);
         if (empty($childVersions)) {
             throw new \LogicException("No historic version for library {$childReleaseName} matches constraint {$historicConstraintName}");
         }
         // Check if to == from version
         $childHistoricVersion = reset($childVersions);
         if ($childHistoricVersion->getValue() === $childNewRelease->getVersion()->getValue()) {
             continue;
         }
         // Recursively generate historic tree
         $childChangelog = $this->getChangelogLibrary($childNewRelease, $childHistoricVersion);
         $historicRelease->addItem($childChangelog);
     }
     return $historicRelease;
 }