Skip to content

Commit 0bdf854

Browse files
committed
Merge pull request wikimedia#102 from webflo/master
Resolve the self.version contraint through packages from the root package
2 parents 4c022be + 1000cdb commit 0bdf854

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sudo: false
1313

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

1919
script: composer test

src/Merge/ExtraPackage.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,24 @@ protected function replaceSelfVersionDependencies(
440440
$prettyVersion = $root->getPrettyVersion();
441441
$vp = new VersionParser();
442442

443+
$method = 'get' . ucfirst($linkType['method']);
444+
$packages = $root->$method();
445+
443446
return array_map(
444-
function ($link) use ($linkType, $version, $prettyVersion, $vp) {
447+
function ($link) use ($linkType, $version, $prettyVersion, $vp, $packages) {
445448
if ('self.version' === $link->getPrettyConstraint()) {
449+
if (isset($packages[$link->getSource()])) {
450+
/** @var Link $package */
451+
$package = $packages[$link->getSource()];
452+
return new Link(
453+
$link->getSource(),
454+
$link->getTarget(),
455+
$vp->parseConstraints($package->getConstraint()->getPrettyString()),
456+
$linkType['description'],
457+
$package->getPrettyConstraint()
458+
);
459+
}
460+
446461
return new Link(
447462
$link->getSource(),
448463
$link->getTarget(),

tests/phpunit/MergePluginTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,49 @@ function ($args) use ($that) {
845845
$this->assertEquals(0, count($extraInstalls));
846846
}
847847

848+
/**
849+
* Test replace link with self.version as version constraint.
850+
*/
851+
public function testSelfVersionNoRootVersion()
852+
{
853+
$that = $this;
854+
$dir = $this->fixtureDir(__FUNCTION__);
855+
$root = $this->rootFromJson("{$dir}/composer.json");
856+
857+
$root->setReplaces(Argument::type('array'))->will(
858+
function ($args) use ($that) {
859+
$replace = $args[0];
860+
$that->assertEquals(3, count($replace));
861+
862+
$that->assertArrayHasKey('foo/bar', $replace);
863+
$that->assertArrayHasKey('foo/baz', $replace);
864+
$that->assertArrayHasKey('foo/xyzzy', $replace);
865+
866+
$that->assertTrue($replace['foo/bar'] instanceof Link);
867+
$that->assertTrue($replace['foo/baz'] instanceof Link);
868+
$that->assertTrue($replace['foo/xyzzy'] instanceof Link);
869+
870+
$that->assertEquals(
871+
'~8.0',
872+
$replace['foo/bar']->getPrettyConstraint()
873+
);
874+
$that->assertEquals(
875+
'~8.0',
876+
$replace['foo/baz']->getPrettyConstraint()
877+
);
878+
$that->assertEquals(
879+
'~1.0',
880+
$replace['foo/xyzzy']->getPrettyConstraint()
881+
);
882+
}
883+
);
884+
885+
$root->getRequires()->shouldNotBeCalled();
886+
887+
$extraInstalls = $this->triggerPlugin($root->reveal(), $dir);
888+
$this->assertEquals(0, count($extraInstalls));
889+
}
890+
848891

849892
/**
850893
* Given a root package with minimum-stability=beta
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "foo/root",
3+
"replace": {
4+
"foo/bar": "~8.0"
5+
},
6+
"extra": {
7+
"merge-plugin": {
8+
"include": "composer.local.json"
9+
}
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "foo/bar",
3+
"replace": {
4+
"foo/baz": "self.version",
5+
"foo/xyzzy": "~1.0"
6+
}
7+
}

0 commit comments

Comments
 (0)