From d6620195e593602a42b3de0c6e4f2d7ddaf19bea Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Apr 2015 10:38:42 +0100 Subject: [PATCH] Prioritize repository over package versions in the default policy, fixes #3509 --- doc/dev/DefaultPolicy.md | 14 ++++----- .../DependencyResolver/DefaultPolicy.php | 4 +-- ...l-prefers-repos-over-package-versions.test | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/install-prefers-repos-over-package-versions.test diff --git a/doc/dev/DefaultPolicy.md b/doc/dev/DefaultPolicy.md index 61db2bf15..65d0710df 100644 --- a/doc/dev/DefaultPolicy.md +++ b/doc/dev/DefaultPolicy.md @@ -12,6 +12,13 @@ resulting order in which the solver will try to install them. The rules are to be applied in the order of these descriptions. +### Repository priorities + +Packages Repo1.Av1, Repo2.Av1 + +* priority(Repo1) >= priority(Repo2) => (Repo1.Av1, Repo2.Av1) +* priority(Repo1) < priority(Repo2) => (Repo2.Av1, Repo1.Av1) + ### Package versions Packages: Av1, Av2, Av3 @@ -22,13 +29,6 @@ Request: install A * (Av3) -### Repository priorities - -Packages Repo1.Av1, Repo2.Av1 - -* priority(Repo1) >= priority(Repo2) => (Repo1.Av1, Repo2.Av1) -* priority(Repo1) < priority(Repo2) => (Repo2.Av1, Repo1.Av1) - ### Virtual Packages (provides) Packages Av1, Bv1 diff --git a/src/Composer/DependencyResolver/DefaultPolicy.php b/src/Composer/DependencyResolver/DefaultPolicy.php index b169c10fe..440d6856c 100644 --- a/src/Composer/DependencyResolver/DefaultPolicy.php +++ b/src/Composer/DependencyResolver/DefaultPolicy.php @@ -82,10 +82,10 @@ class DefaultPolicy implements PolicyInterface } foreach ($packages as &$literals) { - $literals = $this->pruneToBestVersion($pool, $literals); - $literals = $this->pruneToHighestPriorityOrInstalled($pool, $installedMap, $literals); + $literals = $this->pruneToBestVersion($pool, $literals); + $literals = $this->pruneRemoteAliases($pool, $literals); } diff --git a/tests/Composer/Test/Fixtures/installer/install-prefers-repos-over-package-versions.test b/tests/Composer/Test/Fixtures/installer/install-prefers-repos-over-package-versions.test new file mode 100644 index 000000000..eaf111e5b --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/install-prefers-repos-over-package-versions.test @@ -0,0 +1,30 @@ +--TEST-- +Install prefers higher priority repositories over higher priority package versions +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.0.0" } + ] + }, + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.1.0" }, + { "name": "b/b", "version": "1.1.0" }, + { "name": "b/b", "version": "1.0.0" } + ] + } + ], + "require": { + "a/a": "*", + "b/b": "*" + } +} +--RUN-- +install +--EXPECT-- +Installing a/a (1.0.0) +Installing b/b (1.1.0)