Skip to content

Commit 585dd28

Browse files
bug #685 Fix Unpacker failing on Intervals::compactConstraint() (nicolas-grekas)
This PR was merged into the 1.8-dev branch. Discussion ---------- Fix Unpacker failing on Intervals::compactConstraint() Fix #678 Commits ------- d7105c8 Fix Unpacker failing on Intervals::compactConstraint()
2 parents 115e67f + d7105c8 commit 585dd28

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/Flex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
120120
$this->config = $composer->getConfig();
121121
$this->options = $this->initOptions();
122122

123+
$symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? null));
124+
123125
if ($composer2 = version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '<=')) {
124126
$rfs = Factory::createHttpDownloader($this->io, $this->config);
125127

126128
$this->downloader = $downloader = new Downloader($composer, $io, $rfs);
127129
$this->downloader->setFlexId($this->getFlexId());
128130

129-
$symfonyRequire = getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? null);
130131
if ($symfonyRequire) {
131132
$this->filter = new PackageFilter($io, $symfonyRequire, $this->downloader);
132133
}
@@ -136,7 +137,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
136137
$rfs = Factory::createRemoteFilesystem($this->io, $this->config);
137138
$this->rfs = $rfs = new ParallelDownloader($this->io, $this->config, $rfs->getOptions(), $rfs->isTlsDisabled());
138139

139-
$symfonyRequire = getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? null);
140140
$this->downloader = $downloader = new Downloader($composer, $io, $this->rfs);
141141
$this->downloader->setFlexId($this->getFlexId());
142142

src/Unpacker.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Composer\Repository\RepositorySet;
2626
use Composer\Semver\Constraint\MultiConstraint;
2727
use Composer\Semver\Intervals;
28+
use Composer\Semver\VersionParser;
2829
use Symfony\Flex\Unpack\Operation;
2930
use Symfony\Flex\Unpack\Result;
3031

@@ -33,12 +34,14 @@ class Unpacker
3334
private $composer;
3435
private $resolver;
3536
private $dryRun;
37+
private $versionParser;
3638

3739
public function __construct(Composer $composer, PackageResolver $resolver, bool $dryRun)
3840
{
3941
$this->composer = $composer;
4042
$this->resolver = $resolver;
4143
$this->dryRun = $dryRun;
44+
$this->versionParser = new VersionParser();
4245
}
4346

4447
public function unpack(Operation $op, Result $result = null, &$links = []): Result
@@ -101,7 +104,7 @@ public function unpack(Operation $op, Result $result = null, &$links = []): Resu
101104
$linkType = $package['dev'] ? 'require-dev' : 'require';
102105

103106
if (isset($links[$linkName])) {
104-
$links[$linkName]['constraints'][] = $constraint;
107+
$links[$linkName]['constraints'][] = $this->versionParser->parseConstraints($constraint);
105108
if ('require' === $linkType) {
106109
$links[$linkName]['type'] = 'require';
107110
}
@@ -138,16 +141,16 @@ public function unpack(Operation $op, Result $result = null, &$links = []): Resu
138141

139142
// removes package from "require-dev", because it will be moved to "require"
140143
// save stored constraint
141-
$link['constraints'][] = $jsonStored['require-dev'][$link['name']];
144+
$link['constraints'][] = $this->versionParser->parseConstraints($jsonStored['require-dev'][$link['name']]);
142145
$jsonManipulator->removeSubNode('require-dev', $link['name']);
143146
}
144147

145148
$constraint = class_exists(Intervals::class, false)
146-
? Intervals::compactConstraint(MultiConstraint::create($link['constraints']))->getPrettyString()
149+
? Intervals::compactConstraint(MultiConstraint::create($link['constraints']))
147150
: end($link['constraints'])
148151
;
149152

150-
if (!$jsonManipulator->addLink($link['type'], $link['name'], $constraint, $op->shouldSort())) {
153+
if (!$jsonManipulator->addLink($link['type'], $link['name'], $constraint->getPrettyString(), $op->shouldSort())) {
151154
throw new \RuntimeException(sprintf('Unable to unpack package "%s".', $link['name']));
152155
}
153156
}

tests/FlexTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Composer\Repository\RepositoryManager;
2626
use Composer\Repository\WritableRepositoryInterface;
2727
use Composer\Script\Event;
28+
use Composer\Semver\Constraint\MatchAllConstraint;
2829
use PHPUnit\Framework\TestCase;
2930
use Symfony\Component\Console\Output\OutputInterface;
3031
use Symfony\Flex\Configurator;
@@ -99,7 +100,7 @@ public function testActivateLoadsClasses()
99100
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
100101

101102
$package = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
102-
$package->method('getRequires')->willReturn([new Link('dummy', 'symfony/flex')]);
103+
$package->method('getRequires')->willReturn([new Link('dummy', 'symfony/flex', class_exists(MatchAllConstraint::class) ? new MatchAllConstraint() : null)]);
103104

104105
$composer = $this->mockComposer($this->mockLocker(), $package, Factory::createConfig($io));
105106
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {

tests/UnpackerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Composer\Package\Package;
88
use Composer\Repository\InstalledArrayRepository;
99
use Composer\Repository\RepositoryManager;
10+
use Composer\Semver\Constraint\MatchAllConstraint;
1011
use PHPUnit\Framework\TestCase;
1112
use Symfony\Flex\PackageResolver;
1213
use Symfony\Flex\Unpack\Operation;
@@ -44,7 +45,7 @@ public function testDoNotDuplicateEntry(): void
4445
// Setup packages
4546

4647
$realPkg = new Package('real', '1.0.0', '1.0.0');
47-
$realPkgLink = new Link('lorem', 'real', null, 'wraps', '1.0.0');
48+
$realPkgLink = new Link('lorem', 'real', class_exists(MatchAllConstraint::class) ? new MatchAllConstraint() : null, 'wraps', '1.0.0');
4849

4950
$virtualPkgFoo = new Package('pack_foo', '1.0.0', '1.0.0');
5051
$virtualPkgFoo->setType('symfony-pack');

0 commit comments

Comments
 (0)