Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sudo: false

before_script:
- travis_retry composer self-update
- if [ "$TRAVIS_PHP_VERSION" == "5.3.3" ]; then composer config disable-tls true; fi
- if [ "$TRAVIS_PHP_VERSION" == "5.3.3" ]; then composer config disable-tls true; composer config secure-http false; fi
- travis_retry composer install --prefer-source --no-interaction

script: composer test
Expand Down
17 changes: 16 additions & 1 deletion src/Merge/ExtraPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,24 @@ protected function replaceSelfVersionDependencies(
$prettyVersion = $root->getPrettyVersion();
$vp = new VersionParser();

$method = 'get' . ucfirst($linkType['method']);
$packages = $root->$method();

return array_map(
function ($link) use ($linkType, $version, $prettyVersion, $vp) {
function ($link) use ($linkType, $version, $prettyVersion, $vp, $packages) {
if ('self.version' === $link->getPrettyConstraint()) {
if (isset($packages[$link->getSource()])) {
/** @var Link $package */
$package = $packages[$link->getSource()];
return new Link(
$link->getSource(),
$link->getTarget(),
$vp->parseConstraints($package->getConstraint()->getPrettyString()),
$linkType['description'],
$package->getPrettyConstraint()
);
}

return new Link(
$link->getSource(),
$link->getTarget(),
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/MergePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,49 @@ function ($args) use ($that) {
$this->assertEquals(0, count($extraInstalls));
}

/**
* Test replace link with self.version as version constraint.
*/
public function testSelfVersionNoRootVersion()
{
$that = $this;
$dir = $this->fixtureDir(__FUNCTION__);
$root = $this->rootFromJson("{$dir}/composer.json");

$root->setReplaces(Argument::type('array'))->will(
function ($args) use ($that) {
$replace = $args[0];
$that->assertEquals(3, count($replace));

$that->assertArrayHasKey('foo/bar', $replace);
$that->assertArrayHasKey('foo/baz', $replace);
$that->assertArrayHasKey('foo/xyzzy', $replace);

$that->assertTrue($replace['foo/bar'] instanceof Link);
$that->assertTrue($replace['foo/baz'] instanceof Link);
$that->assertTrue($replace['foo/xyzzy'] instanceof Link);

$that->assertEquals(
'~8.0',
$replace['foo/bar']->getPrettyConstraint()
);
$that->assertEquals(
'~8.0',
$replace['foo/baz']->getPrettyConstraint()
);
$that->assertEquals(
'~1.0',
$replace['foo/xyzzy']->getPrettyConstraint()
);
}
);

$root->getRequires()->shouldNotBeCalled();

$extraInstalls = $this->triggerPlugin($root->reveal(), $dir);
$this->assertEquals(0, count($extraInstalls));
}


/**
* Given a root package with minimum-stability=beta
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/fixtures/testSelfVersionNoRootVersion/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "foo/root",
"replace": {
"foo/bar": "~8.0"
},
"extra": {
"merge-plugin": {
"include": "composer.local.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "foo/bar",
"replace": {
"foo/baz": "self.version",
"foo/xyzzy": "~1.0"
}
}