2022-02-23 15:58:18 +00:00
< ? php declare ( strict_types = 1 );
2011-04-05 15:37:19 +00:00
/*
2011-04-16 12:42:35 +00:00
* This file is part of Composer .
2011-04-05 15:37:19 +00:00
*
2011-04-16 12:42:35 +00:00
* ( c ) Nils Adermann < naderman @ naderman . de >
* Jordi Boggiano < j . boggiano @ seld . be >
2011-04-05 15:37:19 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2015-10-13 09:34:02 +00:00
2011-04-05 15:37:19 +00:00
namespace Composer\Test\DependencyResolver ;
2016-03-24 22:19:40 +00:00
use Composer\IO\NullIO ;
2011-05-23 00:18:11 +00:00
use Composer\Repository\ArrayRepository ;
2020-01-15 14:03:11 +00:00
use Composer\Repository\LockArrayRepository ;
2011-04-05 15:37:19 +00:00
use Composer\DependencyResolver\DefaultPolicy ;
2021-10-16 08:16:06 +00:00
use Composer\DependencyResolver\Operation\InstallOperation ;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation ;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation ;
use Composer\DependencyResolver\Operation\UninstallOperation ;
use Composer\DependencyResolver\Operation\UpdateOperation ;
2011-04-05 15:37:19 +00:00
use Composer\DependencyResolver\Request ;
use Composer\DependencyResolver\Solver ;
2012-02-18 23:15:23 +00:00
use Composer\DependencyResolver\SolverProblemsException ;
2022-02-23 15:57:47 +00:00
use Composer\Package\PackageInterface ;
2011-05-23 00:18:11 +00:00
use Composer\Package\Link ;
2018-09-10 13:23:40 +00:00
use Composer\Repository\RepositorySet ;
2018-11-12 14:23:32 +00:00
use Composer\Test\TestCase ;
2015-09-24 14:32:36 +00:00
use Composer\Semver\Constraint\MultiConstraint ;
2020-05-26 17:55:40 +00:00
use Composer\Semver\Constraint\MatchAllConstraint ;
2021-10-16 08:16:06 +00:00
use Composer\DependencyResolver\Pool ;
2011-04-05 15:37:19 +00:00
2011-11-20 14:06:12 +00:00
class SolverTest extends TestCase
2011-04-05 15:37:19 +00:00
{
2021-10-16 08:16:06 +00:00
/** @var RepositorySet */
2018-09-10 13:23:40 +00:00
protected $repoSet ;
2021-10-16 08:16:06 +00:00
/** @var ArrayRepository */
2011-08-05 08:08:21 +00:00
protected $repo ;
2021-10-16 08:16:06 +00:00
/** @var LockArrayRepository */
2018-09-13 13:23:05 +00:00
protected $repoLocked ;
2021-10-16 08:16:06 +00:00
/** @var Request */
2011-08-05 08:08:21 +00:00
protected $request ;
2021-10-16 08:16:06 +00:00
/** @var DefaultPolicy */
2011-08-05 08:08:21 +00:00
protected $policy ;
2021-10-16 08:16:06 +00:00
/** @var Solver|null */
2018-09-12 09:49:09 +00:00
protected $solver ;
2021-10-16 08:16:06 +00:00
/** @var Pool */
2020-01-30 14:23:22 +00:00
protected $pool ;
2011-08-05 08:08:21 +00:00
2021-12-08 16:03:05 +00:00
public function setUp () : void
2011-04-05 15:37:19 +00:00
{
2020-01-30 19:21:17 +00:00
$this -> repoSet = new RepositorySet ();
2011-08-05 08:08:21 +00:00
$this -> repo = new ArrayRepository ;
2020-01-15 14:03:11 +00:00
$this -> repoLocked = new LockArrayRepository ;
2011-08-05 08:08:21 +00:00
2019-11-07 20:51:53 +00:00
$this -> request = new Request ( $this -> repoLocked );
2011-08-05 08:08:21 +00:00
$this -> policy = new DefaultPolicy ;
}
2022-02-18 09:38:54 +00:00
public function testSolverInstallSingle () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-08-05 08:08:21 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-08-05 08:08:21 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverRemoveIfNotRequested () : void
2012-04-27 16:13:37 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
2012-04-27 16:13:37 +00:00
$this -> reposComplete ();
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'remove' , 'package' => $packageA ],
]);
2012-04-27 16:13:37 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallNonExistingPackageFails () : void
2012-02-19 13:55:14 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '1.0' ));
2012-02-19 13:55:14 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'B' , self :: getVersionConstraint ( '==' , '1' ));
2012-02-19 13:55:14 +00:00
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2012-02-19 13:55:14 +00:00
try {
$transaction = $this -> solver -> solve ( $this -> request );
2012-03-18 19:41:10 +00:00
$this -> fail ( 'Unsolvable conflict did not result in exception.' );
2012-02-19 13:55:14 +00:00
} catch ( SolverProblemsException $e ) {
2012-03-18 19:41:10 +00:00
$problems = $e -> getProblems ();
2017-11-30 14:58:10 +00:00
$this -> assertCount ( 1 , $problems );
2013-04-25 09:26:34 +00:00
$this -> assertEquals ( 2 , $e -> getCode ());
2020-04-14 22:58:35 +00:00
$this -> assertEquals ( " \n - Root composer.json requires b, it could not be found in any version, there may be a typo in the package name. " , $problems [ 0 ] -> getPrettyString ( $this -> repoSet , $this -> request , $this -> pool , false ));
2012-02-19 13:55:14 +00:00
}
}
2022-02-18 09:38:54 +00:00
public function testSolverInstallSamePackageFromDifferentRepositories () : void
2012-03-06 09:11:45 +00:00
{
$repo1 = new ArrayRepository ;
$repo2 = new ArrayRepository ;
2022-11-24 13:39:08 +00:00
$repo1 -> addPackage ( $foo1 = self :: getPackage ( 'foo' , '1' ));
$repo2 -> addPackage ( $foo2 = self :: getPackage ( 'foo' , '1' ));
2012-03-06 09:11:45 +00:00
2018-09-10 13:23:40 +00:00
$this -> repoSet -> addRepository ( $repo1 );
$this -> repoSet -> addRepository ( $repo2 );
2012-03-06 09:11:45 +00:00
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'foo' );
2012-03-06 09:11:45 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $foo1 ],
]);
2012-03-06 09:11:45 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverInstallWithDeps () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '1.1' ));
2011-04-05 15:37:19 +00:00
2022-11-24 13:39:08 +00:00
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '<' , '1.1' ), Link :: TYPE_REQUIRE )]);
2011-04-05 15:37:19 +00:00
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2011-04-05 15:37:19 +00:00
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-04-05 15:37:19 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-08-05 08:08:21 +00:00
}
2011-04-05 15:37:19 +00:00
2022-02-18 09:38:54 +00:00
public function testSolverInstallHonoursNotEqualOperator () : void
2012-06-19 01:08:36 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageB11 = self :: getPackage ( 'B' , '1.1' ));
$this -> repo -> addPackage ( $newPackageB12 = self :: getPackage ( 'B' , '1.2' ));
$this -> repo -> addPackage ( $newPackageB13 = self :: getPackage ( 'B' , '1.3' ));
2012-06-19 01:08:36 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([
'b' => new Link ( 'A' , 'B' , new MultiConstraint ([
2022-11-24 13:39:08 +00:00
self :: getVersionConstraint ( '<=' , '1.3' ),
self :: getVersionConstraint ( '<>' , '1.3' ),
self :: getVersionConstraint ( '!=' , '1.2' ),
2022-08-17 12:20:07 +00:00
]), Link :: TYPE_REQUIRE ),
]);
2012-06-19 01:08:36 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2012-06-19 01:08:36 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $newPackageB11 ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2012-06-19 01:08:36 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverInstallWithDepsInOrder () : void
2012-06-04 21:30:55 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '1.0' ));
2012-06-04 21:30:55 +00:00
2022-08-17 12:20:07 +00:00
$packageB -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
'c' => new Link ( 'B' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
$packageC -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'C' , 'A' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-06-04 21:30:55 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
$this -> request -> requireName ( 'B' );
$this -> request -> requireName ( 'C' );
2012-06-04 21:30:55 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'install' , 'package' => $packageC ],
[ 'job' => 'install' , 'package' => $packageB ],
]);
2012-06-04 21:30:55 +00:00
}
2021-10-02 17:02:22 +00:00
/**
* This test covers a particular behavior of the solver related to packages with the same name and version ,
* but different requirements on other packages .
* Imagine you had multiple instances of packages ( same name / version ) with e . g . different dists depending on what other related package they were " built " for .
*
* An example people can probably relate to , so it was chosen here for better readability :
* - PHP versions 8.0 . 10 and 7.4 . 23 could be a package
* - ext - foobar 1.0 . 0 could be a package , but it must be built separately for each PHP x . y series
* - thus each of the ext - foobar packages lists the " PHP " package as a dependency
*
* This is not something that can happen with packages on e . g . Packagist , but custom installers with custom repositories might do something like this ;
* in fact , some PaaSes do the exact thing above , installing binary builds of PHP and extensions as Composer packages with a custom installer in a separate step before the " userland " `composer install` .
2021-10-27 14:18:24 +00:00
*
2021-10-02 17:02:22 +00:00
* If version selectors are sufficiently permissive ( e . g . " ourcustom/php " : " * " , " ourcustom/ext-foobar " : " * " ), then it may happen that the Solver won 't pick the highest possible PHP version, as it has already settled on an "ext-foobar" (they' re all the same version to the Solver , it doesn ' t know about the different requirements in each of the otherwise identical packages ) if that was listed in " require " before " php " .
* That 's "unfixable", and not even broken, behavior (what if the "ext-foobar" has higher versions for the lower "PHP"? who wins then? any combination of the packages is "correct"), but it shouldn' t randomly change .
* This test asserts this behavior to prevent regressions .
*
* CAUTION : IF THIS TEST EVER FAILS , SOLVER BEHAVIOR HAS CHANGED AND MAY BREAK DOWNSTREAM USERS
*/
2022-02-18 09:38:54 +00:00
public function testSolverMultiPackageNameVersionResolutionDependsOnRequireOrder () : void
2021-10-02 17:02:22 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $php74 = self :: getPackage ( 'ourcustom/PHP' , '7.4.23' ));
$this -> repo -> addPackage ( $php80 = self :: getPackage ( 'ourcustom/PHP' , '8.0.10' ));
$this -> repo -> addPackage ( $extForPhp74 = self :: getPackage ( 'ourcustom/ext-foobar' , '1.0' ));
$this -> repo -> addPackage ( $extForPhp80 = self :: getPackage ( 'ourcustom/ext-foobar' , '1.0' ));
2021-10-02 17:02:22 +00:00
2022-08-17 12:20:07 +00:00
$extForPhp74 -> setRequires ([
'ourcustom/php' => new Link ( 'ourcustom/ext-foobar' , 'ourcustom/PHP' , new MultiConstraint ([
2022-11-24 13:39:08 +00:00
self :: getVersionConstraint ( '>=' , '7.4.0' ),
self :: getVersionConstraint ( '<' , '7.5.0' ),
2022-08-17 12:20:07 +00:00
]), Link :: TYPE_REQUIRE ),
]);
$extForPhp80 -> setRequires ([
'ourcustom/php' => new Link ( 'ourcustom/ext-foobar' , 'ourcustom/PHP' , new MultiConstraint ([
2022-11-24 13:39:08 +00:00
self :: getVersionConstraint ( '>=' , '8.0.0' ),
self :: getVersionConstraint ( '<' , '8.1.0' ),
2022-08-17 12:20:07 +00:00
]), Link :: TYPE_REQUIRE ),
]);
2021-10-02 17:02:22 +00:00
$this -> reposComplete ();
$this -> request -> requireName ( 'ourcustom/PHP' );
$this -> request -> requireName ( 'ourcustom/ext-foobar' );
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $php80 ],
[ 'job' => 'install' , 'package' => $extForPhp80 ],
]);
2021-10-02 17:02:22 +00:00
// now we flip the requirements around: we request "ext-foobar" before "php"
// because the ext-foobar package that requires php74 comes first in the repo, and the one that requires php80 second, the solver will pick the one for php74, and then, as it is a dependency, also php74
// this is because both packages have the same name and version; just their requirements differ
// and because no other constraint forces a particular version of package "php"
$this -> request = new Request ( $this -> repoLocked );
$this -> request -> requireName ( 'ourcustom/ext-foobar' );
$this -> request -> requireName ( 'ourcustom/PHP' );
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $php74 ],
[ 'job' => 'install' , 'package' => $extForPhp74 ],
]);
2021-10-02 17:02:22 +00:00
}
/**
* This test is almost the same as above , except we ' re inserting the package with the requirement on the other package in a different order , asserting that if that is done , the order of requirements no longer matters
*
* CAUTION : IF THIS TEST EVER FAILS , SOLVER BEHAVIOR HAS CHANGED AND MAY BREAK DOWNSTREAM USERS
*/
2022-02-18 09:38:54 +00:00
public function testSolverMultiPackageNameVersionResolutionIsIndependentOfRequireOrderIfOrderedDescendingByRequirement () : void
2021-10-02 17:02:22 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $php74 = self :: getPackage ( 'ourcustom/PHP' , '7.4' ));
$this -> repo -> addPackage ( $php80 = self :: getPackage ( 'ourcustom/PHP' , '8.0' ));
$this -> repo -> addPackage ( $extForPhp80 = self :: getPackage ( 'ourcustom/ext-foobar' , '1.0' )); // note we are inserting this one into the repo first, unlike in the previous test
$this -> repo -> addPackage ( $extForPhp74 = self :: getPackage ( 'ourcustom/ext-foobar' , '1.0' ));
2021-10-02 17:02:22 +00:00
2022-08-17 12:20:07 +00:00
$extForPhp80 -> setRequires ([
'ourcustom/php' => new Link ( 'ourcustom/ext-foobar' , 'ourcustom/PHP' , new MultiConstraint ([
2022-11-24 13:39:08 +00:00
self :: getVersionConstraint ( '>=' , '8.0.0' ),
self :: getVersionConstraint ( '<' , '8.1.0' ),
2022-08-17 12:20:07 +00:00
]), Link :: TYPE_REQUIRE ),
]);
$extForPhp74 -> setRequires ([
'ourcustom/php' => new Link ( 'ourcustom/ext-foobar' , 'ourcustom/PHP' , new MultiConstraint ([
2022-11-24 13:39:08 +00:00
self :: getVersionConstraint ( '>=' , '7.4.0' ),
self :: getVersionConstraint ( '<' , '7.5.0' ),
2022-08-17 12:20:07 +00:00
]), Link :: TYPE_REQUIRE ),
]);
2021-10-02 17:02:22 +00:00
$this -> reposComplete ();
$this -> request -> requireName ( 'ourcustom/PHP' );
$this -> request -> requireName ( 'ourcustom/ext-foobar' );
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $php80 ],
[ 'job' => 'install' , 'package' => $extForPhp80 ],
]);
2021-10-02 17:02:22 +00:00
// unlike in the previous test, the order of requirements no longer matters now
$this -> request = new Request ( $this -> repoLocked );
$this -> request -> requireName ( 'ourcustom/ext-foobar' );
$this -> request -> requireName ( 'ourcustom/PHP' );
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $php80 ],
[ 'job' => 'install' , 'package' => $extForPhp80 ],
]);
2021-10-02 17:02:22 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverFixLocked () : void
2011-08-20 22:19:47 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
2011-08-20 22:19:47 +00:00
$this -> reposComplete ();
2019-11-07 20:51:53 +00:00
$this -> request -> fixPackage ( $packageA );
2011-08-20 22:19:47 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([]);
2011-08-20 22:19:47 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverFixLockedWithAlternative () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '1.0' ));
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2019-11-07 20:51:53 +00:00
$this -> request -> fixPackage ( $packageA );
2011-08-05 08:08:21 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([]);
2011-08-05 08:08:21 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateDoesOnlyUpdate () : void
2012-01-15 13:15:53 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repoLocked -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '1.1' ));
2012-01-15 13:15:53 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0.0.0' ), Link :: TYPE_REQUIRE )]);
2012-01-15 13:15:53 +00:00
2019-11-07 20:51:53 +00:00
$this -> request -> fixPackage ( $packageA );
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'B' , self :: getVersionConstraint ( '=' , '1.1.0.0' ));
2012-01-15 13:15:53 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'update' , 'from' => $packageB , 'to' => $newPackageB ],
]);
2012-01-15 13:15:53 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateSingle () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '1.1' ));
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-08-05 08:08:21 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'update' , 'from' => $packageA , 'to' => $newPackageA ],
]);
2011-08-05 08:08:21 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateAll () : void
2012-02-19 15:59:04 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repoLocked -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '1.1' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '1.1' ));
2012-02-19 15:59:04 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , new MatchAllConstraint (), Link :: TYPE_REQUIRE )]);
$newPackageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , new MatchAllConstraint (), Link :: TYPE_REQUIRE )]);
2012-02-19 15:59:04 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2012-02-19 15:59:04 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'update' , 'from' => $packageB , 'to' => $newPackageB ],
[ 'job' => 'update' , 'from' => $packageA , 'to' => $newPackageA ],
]);
2012-02-19 15:59:04 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateCurrent () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '1.0' ));
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-08-05 08:08:21 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([]);
2011-08-05 08:08:21 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateOnlyUpdatesSelectedPackage () : void
2012-02-18 15:55:45 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repoLocked -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageAnewer = self :: getPackage ( 'A' , '1.1' ));
$this -> repo -> addPackage ( $packageBnewer = self :: getPackage ( 'B' , '1.1' ));
2012-02-18 15:55:45 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2019-11-07 20:51:53 +00:00
$this -> request -> fixPackage ( $packageB );
2012-02-18 15:55:45 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'update' , 'from' => $packageA , 'to' => $packageAnewer ],
]);
2012-02-18 15:55:45 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateConstrained () : void
2011-12-24 13:15:10 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '1.2' ));
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '2.0' ));
2011-12-24 13:15:10 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '<' , '2.0.0.0' ));
2011-12-24 13:15:10 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([[
2011-12-24 13:15:10 +00:00
'job' => 'update' ,
'from' => $packageA ,
'to' => $newPackageA ,
2022-08-17 12:20:07 +00:00
]]);
2011-12-24 13:15:10 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateFullyConstrained () : void
2011-12-24 13:15:10 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '1.2' ));
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '2.0' ));
2011-12-24 13:15:10 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '<' , '2.0.0.0' ));
2012-02-18 15:55:45 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([[
2012-02-18 15:55:45 +00:00
'job' => 'update' ,
'from' => $packageA ,
'to' => $newPackageA ,
2022-08-17 12:20:07 +00:00
]]);
2012-02-18 15:55:45 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverUpdateFullyConstrainedPrunesInstalledPackages () : void
2012-02-18 15:55:45 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repoLocked -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '1.2' ));
$this -> repo -> addPackage ( self :: getPackage ( 'A' , '2.0' ));
2012-02-18 15:55:45 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '<' , '2.0.0.0' ));
2011-12-24 13:15:10 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[
2019-11-08 14:56:46 +00:00
'job' => 'remove' ,
'package' => $packageB ,
2022-08-17 12:20:07 +00:00
],
[
2012-04-27 16:13:37 +00:00
'job' => 'update' ,
'from' => $packageA ,
'to' => $newPackageA ,
2022-08-17 12:20:07 +00:00
],
]);
2011-12-24 13:15:10 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverAllJobs () : void
2011-08-05 08:08:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageD = self :: getPackage ( 'D' , '1.0' ));
$this -> repoLocked -> addPackage ( $oldPackageC = self :: getPackage ( 'C' , '1.0' ));
2011-11-20 14:06:12 +00:00
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '2.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '1.1' ));
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '1.1' ));
$this -> repo -> addPackage ( self :: getPackage ( 'D' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '<' , '1.1' ), Link :: TYPE_REQUIRE )]);
2011-08-05 08:08:21 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
$this -> request -> requireName ( 'C' );
2011-08-05 08:08:21 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'remove' , 'package' => $packageD ],
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'update' , 'from' => $oldPackageC , 'to' => $packageC ],
]);
2011-08-05 08:08:21 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverThreeAlternativeRequireAndConflict () : void
2011-08-21 10:30:06 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '2.0' ));
$this -> repo -> addPackage ( $middlePackageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '1.1' ));
$this -> repo -> addPackage ( $oldPackageB = self :: getPackage ( 'B' , '0.9' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '<' , '1.1' ), Link :: TYPE_REQUIRE )]);
$packageA -> setConflicts ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '<' , '1.0' ), Link :: TYPE_CONFLICT )]);
2011-08-21 10:30:06 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-08-21 10:30:06 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $middlePackageB ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-08-21 10:30:06 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSolverObsolete () : void
2011-08-21 11:08:34 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repoLocked -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
2022-08-17 12:20:07 +00:00
$packageB -> setReplaces ([ 'a' => new Link ( 'B' , 'A' , new MatchAllConstraint ())]);
2011-08-21 11:08:34 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'B' );
2011-08-21 11:08:34 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'remove' , 'package' => $packageA ],
[ 'job' => 'install' , 'package' => $packageB ],
]);
2011-08-21 11:08:34 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallOneOfTwoAlternatives () : void
2011-08-05 08:17:07 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'A' , '1.0' ));
2011-08-21 03:05:11 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-08-21 03:05:11 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-08-21 03:05:11 +00:00
}
2011-08-05 08:17:07 +00:00
2022-02-18 09:38:54 +00:00
public function testInstallProvider () : void
2011-09-09 08:28:50 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageQ = self :: getPackage ( 'Q' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageQ -> setProvides ([ 'b' => new Link ( 'Q' , 'B' , self :: getVersionConstraint ( '=' , '1.0' ), Link :: TYPE_PROVIDE )]);
2011-09-09 08:28:50 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-09-09 08:28:50 +00:00
2014-02-21 11:25:15 +00:00
// must explicitly pick the provider, so error in this case
2021-12-09 19:55:26 +00:00
self :: expectException ( 'Composer\DependencyResolver\SolverProblemsException' );
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2014-02-21 11:25:15 +00:00
$this -> solver -> solve ( $this -> request );
2011-10-15 18:03:55 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSkipReplacerOfExistingPackage () : void
2011-10-15 18:03:55 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageQ = self :: getPackage ( 'Q' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageQ -> setReplaces ([ 'b' => new Link ( 'Q' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE )]);
2011-10-15 18:03:55 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-10-15 18:03:55 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-10-15 18:03:55 +00:00
}
2022-02-18 09:38:54 +00:00
public function testNoInstallReplacerOfMissingPackage () : void
2011-10-15 18:03:55 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageQ = self :: getPackage ( 'Q' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageQ -> setReplaces ([ 'b' => new Link ( 'Q' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE )]);
2011-10-15 18:03:55 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-10-15 18:03:55 +00:00
2021-12-09 19:55:26 +00:00
self :: expectException ( 'Composer\DependencyResolver\SolverProblemsException' );
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2014-02-21 12:41:21 +00:00
$this -> solver -> solve ( $this -> request );
2011-10-15 18:03:55 +00:00
}
2022-02-18 09:38:54 +00:00
public function testSkipReplacedPackageIfReplacerIsSelected () : void
2011-10-15 18:03:55 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageQ = self :: getPackage ( 'Q' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageQ -> setReplaces ([ 'b' => new Link ( 'Q' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE )]);
2011-10-15 18:03:55 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
$this -> request -> requireName ( 'Q' );
2011-10-15 18:03:55 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageQ ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-09-09 08:28:50 +00:00
}
2022-02-18 09:38:54 +00:00
public function testPickOlderIfNewerConflicts () : void
2011-11-25 22:32:24 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageX = self :: getPackage ( 'X' , '1.0' ));
2022-08-17 12:20:07 +00:00
$packageX -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'X' , 'A' , self :: getVersionConstraint ( '>=' , '2.0.0.0' ), Link :: TYPE_REQUIRE ),
'b' => new Link ( 'X' , 'B' , self :: getVersionConstraint ( '>=' , '2.0.0.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2011-11-25 22:32:24 +00:00
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '2.0.0' ));
$this -> repo -> addPackage ( $newPackageA = self :: getPackage ( 'A' , '2.1.0' ));
$this -> repo -> addPackage ( $newPackageB = self :: getPackage ( 'B' , '2.1.0' ));
2011-11-25 22:32:24 +00:00
2022-11-24 13:39:08 +00:00
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '2.0.0.0' ), Link :: TYPE_REQUIRE )]);
2011-11-25 22:32:24 +00:00
// new package A depends on version of package B that does not exist
// => new package A is not installable
2022-11-24 13:39:08 +00:00
$newPackageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '2.2.0.0' ), Link :: TYPE_REQUIRE )]);
2011-11-25 22:32:24 +00:00
// add a package S replacing both A and B, so that S and B or S and A cannot be simultaneously installed
// but an alternative option for A and B both exists
// this creates a more difficult so solve conflict
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageS = self :: getPackage ( 'S' , '2.0.0' ));
2022-08-17 12:20:07 +00:00
$packageS -> setReplaces ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'S' , 'A' , self :: getVersionConstraint ( '>=' , '2.0.0.0' ), Link :: TYPE_REPLACE ),
'b' => new Link ( 'S' , 'B' , self :: getVersionConstraint ( '>=' , '2.0.0.0' ), Link :: TYPE_REPLACE ),
2022-08-17 12:20:07 +00:00
]);
2011-11-25 22:32:24 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'X' );
2011-11-25 22:32:24 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $newPackageB ],
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'install' , 'package' => $packageX ],
]);
2011-11-25 22:32:24 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallCircularRequire () : void
2011-09-09 08:28:50 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB1 = self :: getPackage ( 'B' , '0.9' ));
$this -> repo -> addPackage ( $packageB2 = self :: getPackage ( 'B' , '1.1' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageB2 -> setRequires ([ 'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
2011-09-09 08:28:50 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2011-09-09 08:28:50 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageB2 ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-09-09 08:28:50 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallAlternativeWithCircularRequire () : void
2011-09-09 08:28:50 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '1.0' ));
$this -> repo -> addPackage ( $packageD = self :: getPackage ( 'D' , '1.0' ));
$packageA -> setRequires ([ 'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageB -> setRequires ([ 'virtual' => new Link ( 'B' , 'Virtual' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageC -> setProvides ([ 'virtual' => new Link ( 'C' , 'Virtual' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_PROVIDE )]);
$packageD -> setProvides ([ 'virtual' => new Link ( 'D' , 'Virtual' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_PROVIDE )]);
2012-02-19 19:08:15 +00:00
2022-11-24 13:39:08 +00:00
$packageC -> setRequires ([ 'a' => new Link ( 'C' , 'A' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE )]);
$packageD -> setRequires ([ 'a' => new Link ( 'D' , 'A' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE )]);
2011-09-09 08:28:50 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
$this -> request -> requireName ( 'C' );
2011-09-09 08:28:50 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'install' , 'package' => $packageC ],
]);
2012-02-18 11:33:55 +00:00
}
/**
2012-02-18 11:37:45 +00:00
* If a replacer D replaces B and C with C not otherwise available ,
* D must be installed instead of the original B .
*/
2022-02-18 09:38:54 +00:00
public function testUseReplacerIfNecessary () : void
2012-02-18 11:33:55 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageD = self :: getPackage ( 'D' , '1.0' ));
$this -> repo -> addPackage ( $packageD2 = self :: getPackage ( 'D' , '1.1' ));
2012-02-18 11:33:55 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
'c' => new Link ( 'A' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-18 11:33:55 +00:00
2022-08-17 12:20:07 +00:00
$packageD -> setReplaces ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'D' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE ),
'c' => new Link ( 'D' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-18 11:33:55 +00:00
2022-08-17 12:20:07 +00:00
$packageD2 -> setReplaces ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'D' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE ),
'c' => new Link ( 'D' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REPLACE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-18 11:33:55 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
$this -> request -> requireName ( 'D' );
2012-02-18 11:33:55 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageD2 ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2011-09-25 21:50:54 +00:00
}
2011-09-09 08:28:50 +00:00
2022-02-18 09:38:54 +00:00
public function testIssue265 () : void
2012-02-19 14:35:13 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA1 = self :: getPackage ( 'A' , '2.0.999999-dev' ));
$this -> repo -> addPackage ( $packageA2 = self :: getPackage ( 'A' , '2.1-dev' ));
$this -> repo -> addPackage ( $packageA3 = self :: getPackage ( 'A' , '2.2-dev' ));
$this -> repo -> addPackage ( $packageB1 = self :: getPackage ( 'B' , '2.0.10' ));
$this -> repo -> addPackage ( $packageB2 = self :: getPackage ( 'B' , '2.0.9' ));
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '2.0-dev' ));
$this -> repo -> addPackage ( $packageD = self :: getPackage ( 'D' , '2.0.9' ));
2012-02-19 14:35:13 +00:00
2022-08-17 12:20:07 +00:00
$packageC -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'C' , 'A' , self :: getVersionConstraint ( '>=' , '2.0' ), Link :: TYPE_REQUIRE ),
'd' => new Link ( 'C' , 'D' , self :: getVersionConstraint ( '>=' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-19 14:35:13 +00:00
2022-08-17 12:20:07 +00:00
$packageD -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'D' , 'A' , self :: getVersionConstraint ( '>=' , '2.1' ), Link :: TYPE_REQUIRE ),
'b' => new Link ( 'D' , 'B' , self :: getVersionConstraint ( '>=' , '2.0-dev' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-19 14:35:13 +00:00
2022-11-24 13:39:08 +00:00
$packageB1 -> setRequires ([ 'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '==' , '2.1.0.0-dev' ), Link :: TYPE_REQUIRE )]);
$packageB2 -> setRequires ([ 'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '==' , '2.1.0.0-dev' ), Link :: TYPE_REQUIRE )]);
2012-02-19 14:35:13 +00:00
2022-11-24 13:39:08 +00:00
$packageB2 -> setReplaces ([ 'd' => new Link ( 'B' , 'D' , self :: getVersionConstraint ( '==' , '2.0.9.0' ), Link :: TYPE_REPLACE )]);
2012-02-19 14:35:13 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'C' , self :: getVersionConstraint ( '==' , '2.0.0.0-dev' ));
2012-02-19 14:35:13 +00:00
2021-12-09 19:55:26 +00:00
self :: expectException ( 'Composer\DependencyResolver\SolverProblemsException' );
2012-02-19 14:35:13 +00:00
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2012-02-19 14:35:13 +00:00
$this -> solver -> solve ( $this -> request );
}
2022-02-18 09:38:54 +00:00
public function testConflictResultEmpty () : void
2012-02-18 23:15:23 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
2022-08-17 12:20:07 +00:00
$packageA -> setConflicts ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_CONFLICT ),
2022-08-17 12:20:07 +00:00
]);
2012-02-18 23:15:23 +00:00
$this -> reposComplete ();
2020-06-05 14:41:37 +00:00
$emptyConstraint = new MatchAllConstraint ();
2020-05-01 18:14:04 +00:00
$emptyConstraint -> setPrettyString ( '*' );
$this -> request -> requireName ( 'A' , $emptyConstraint );
$this -> request -> requireName ( 'B' , $emptyConstraint );
2012-02-18 23:15:23 +00:00
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2012-02-18 23:15:23 +00:00
try {
$transaction = $this -> solver -> solve ( $this -> request );
2012-03-18 19:41:10 +00:00
$this -> fail ( 'Unsolvable conflict did not result in exception.' );
2012-02-18 23:15:23 +00:00
} catch ( SolverProblemsException $e ) {
2012-03-18 19:41:10 +00:00
$problems = $e -> getProblems ();
2017-11-30 14:58:10 +00:00
$this -> assertCount ( 1 , $problems );
2012-06-20 17:04:21 +00:00
$msg = " \n " ;
$msg .= " Problem 1 \n " ;
2020-05-01 18:14:04 +00:00
$msg .= " - Root composer.json requires a * -> satisfiable by A[1.0]. \n " ;
2020-01-30 14:51:56 +00:00
$msg .= " - A 1.0 conflicts with B 1.0. \n " ;
2020-05-01 18:14:04 +00:00
$msg .= " - Root composer.json requires b * -> satisfiable by B[1.0]. \n " ;
2020-04-14 22:58:35 +00:00
$this -> assertEquals ( $msg , $e -> getPrettyString ( $this -> repoSet , $this -> request , $this -> pool , false ));
2012-02-18 23:15:23 +00:00
}
}
2022-02-18 09:38:54 +00:00
public function testUnsatisfiableRequires () : void
2012-02-18 23:15:23 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
2012-02-18 23:15:23 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-02-18 23:15:23 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
2012-02-18 23:15:23 +00:00
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2012-02-18 23:15:23 +00:00
try {
$transaction = $this -> solver -> solve ( $this -> request );
2012-03-18 19:41:10 +00:00
$this -> fail ( 'Unsolvable conflict did not result in exception.' );
2012-02-18 23:15:23 +00:00
} catch ( SolverProblemsException $e ) {
2012-03-18 19:41:10 +00:00
$problems = $e -> getProblems ();
2017-11-30 14:58:10 +00:00
$this -> assertCount ( 1 , $problems );
2012-02-19 14:30:53 +00:00
// TODO assert problem properties
2012-06-20 17:04:21 +00:00
$msg = " \n " ;
$msg .= " Problem 1 \n " ;
2020-06-05 14:41:37 +00:00
$msg .= " - Root composer.json requires a * -> satisfiable by A[1.0]. \n " ;
2020-04-23 11:17:22 +00:00
$msg .= " - A 1.0 requires b >= 2.0 -> found B[1.0] but it does not match the constraint. \n " ;
2020-04-14 22:58:35 +00:00
$this -> assertEquals ( $msg , $e -> getPrettyString ( $this -> repoSet , $this -> request , $this -> pool , false ));
2012-06-20 17:04:21 +00:00
}
}
2022-02-18 09:38:54 +00:00
public function testRequireMismatchException () : void
2012-06-20 17:04:21 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageB2 = self :: getPackage ( 'B' , '0.9' ));
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '1.0' ));
$this -> repo -> addPackage ( $packageD = self :: getPackage ( 'D' , '1.0' ));
2012-06-20 17:04:21 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
$packageB -> setRequires ([
2022-11-24 13:39:08 +00:00
'c' => new Link ( 'B' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
$packageC -> setRequires ([
2022-11-24 13:39:08 +00:00
'd' => new Link ( 'C' , 'D' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
$packageD -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'D' , 'B' , self :: getVersionConstraint ( '<' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-06-20 17:04:21 +00:00
$this -> reposComplete ();
2020-06-05 14:41:37 +00:00
$emptyConstraint = new MatchAllConstraint ();
2020-05-01 18:14:04 +00:00
$emptyConstraint -> setPrettyString ( '*' );
$this -> request -> requireName ( 'A' , $emptyConstraint );
2012-06-20 17:04:21 +00:00
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2012-06-20 17:04:21 +00:00
try {
$transaction = $this -> solver -> solve ( $this -> request );
$this -> fail ( 'Unsolvable conflict did not result in exception.' );
} catch ( SolverProblemsException $e ) {
$problems = $e -> getProblems ();
2017-11-30 14:58:10 +00:00
$this -> assertCount ( 1 , $problems );
2012-06-20 17:04:21 +00:00
$msg = " \n " ;
$msg .= " Problem 1 \n " ;
2013-04-26 22:31:22 +00:00
$msg .= " - C 1.0 requires d >= 1.0 -> satisfiable by D[1.0]. \n " ;
$msg .= " - D 1.0 requires b < 1.0 -> satisfiable by B[0.9]. \n " ;
$msg .= " - B 1.0 requires c >= 1.0 -> satisfiable by C[1.0]. \n " ;
2020-01-30 16:11:34 +00:00
$msg .= " - You can only install one version of a package, so only one of these can be installed: B[0.9, 1.0]. \n " ;
2013-04-26 22:31:22 +00:00
$msg .= " - A 1.0 requires b >= 1.0 -> satisfiable by B[1.0]. \n " ;
2020-05-01 18:14:04 +00:00
$msg .= " - Root composer.json requires a * -> satisfiable by A[1.0]. \n " ;
2020-04-14 22:58:35 +00:00
$this -> assertEquals ( $msg , $e -> getPrettyString ( $this -> repoSet , $this -> request , $this -> pool , false ));
2012-02-18 23:15:23 +00:00
}
}
2022-02-18 09:38:54 +00:00
public function testLearnLiteralsWithSortedRuleLiterals () : void
2012-04-01 20:26:10 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageTwig2 = self :: getPackage ( 'twig/twig' , '2.0' ));
$this -> repo -> addPackage ( $packageTwig16 = self :: getPackage ( 'twig/twig' , '1.6' ));
$this -> repo -> addPackage ( $packageTwig15 = self :: getPackage ( 'twig/twig' , '1.5' ));
$this -> repo -> addPackage ( $packageSymfony = self :: getPackage ( 'symfony/symfony' , '2.0' ));
$this -> repo -> addPackage ( $packageTwigBridge = self :: getPackage ( 'symfony/twig-bridge' , '2.0' ));
2012-04-01 20:26:10 +00:00
2022-08-17 12:20:07 +00:00
$packageTwigBridge -> setRequires ([
2022-11-24 13:39:08 +00:00
'twig/twig' => new Link ( 'symfony/twig-bridge' , 'twig/twig' , self :: getVersionConstraint ( '<' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-04-01 20:26:10 +00:00
2022-08-17 12:20:07 +00:00
$packageSymfony -> setReplaces ([
2022-11-24 13:39:08 +00:00
'symfony/twig-bridge' => new Link ( 'symfony/symfony' , 'symfony/twig-bridge' , self :: getVersionConstraint ( '==' , '2.0' ), Link :: TYPE_REPLACE ),
2022-08-17 12:20:07 +00:00
]);
2012-04-01 20:26:10 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'symfony/twig-bridge' );
$this -> request -> requireName ( 'twig/twig' );
2012-04-01 20:26:10 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageTwig16 ],
[ 'job' => 'install' , 'package' => $packageTwigBridge ],
]);
2012-04-01 20:26:10 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallRecursiveAliasDependencies () : void
2012-04-27 17:41:53 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '2.0' ));
$this -> repo -> addPackage ( $packageA2 = self :: getPackage ( 'A' , '2.0' ));
2012-04-27 17:41:53 +00:00
2022-08-17 12:20:07 +00:00
$packageA2 -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '==' , '2.0' ), Link :: TYPE_REQUIRE , '== 2.0' ),
2022-08-17 12:20:07 +00:00
]);
$packageB -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '>=' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-04-27 17:41:53 +00:00
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA2Alias = self :: getAliasPackage ( $packageA2 , '1.1' ));
2012-04-27 17:41:53 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '==' , '1.1.0.0' ));
2012-04-27 17:41:53 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA2 ],
[ 'job' => 'markAliasInstalled' , 'package' => $packageA2Alias ],
]);
2012-04-27 17:41:53 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallDevAlias () : void
2012-04-27 17:41:53 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '2.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
2012-04-27 17:41:53 +00:00
2022-08-17 12:20:07 +00:00
$packageB -> setRequires ([
2022-11-24 13:39:08 +00:00
'a' => new Link ( 'B' , 'A' , self :: getVersionConstraint ( '<' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
2012-04-27 17:41:53 +00:00
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageAAlias = self :: getAliasPackage ( $packageA , '1.1' ));
2012-04-27 17:41:53 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '==' , '2.0' ));
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'B' );
2012-04-27 17:41:53 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'markAliasInstalled' , 'package' => $packageAAlias ],
[ 'job' => 'install' , 'package' => $packageB ],
]);
2012-04-27 17:41:53 +00:00
}
2022-02-18 09:38:54 +00:00
public function testInstallRootAliasesIfAliasOfIsInstalled () : void
2020-11-12 16:05:50 +00:00
{
// root aliased, required
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageAAlias = self :: getAliasPackage ( $packageA , '1.1' ));
2020-11-12 16:05:50 +00:00
$packageAAlias -> setRootPackageAlias ( true );
// root aliased, not required, should still be installed as it is root alias
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageBAlias = self :: getAliasPackage ( $packageB , '1.1' ));
2020-11-12 16:05:50 +00:00
$packageBAlias -> setRootPackageAlias ( true );
// regular alias, not required, alias should not be installed
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageC = self :: getPackage ( 'C' , '1.0' ));
$this -> repo -> addPackage ( $packageCAlias = self :: getAliasPackage ( $packageC , '1.1' ));
2020-11-12 16:05:50 +00:00
$this -> reposComplete ();
2022-11-24 13:39:08 +00:00
$this -> request -> requireName ( 'A' , self :: getVersionConstraint ( '==' , '1.1' ));
$this -> request -> requireName ( 'B' , self :: getVersionConstraint ( '==' , '1.0' ));
$this -> request -> requireName ( 'C' , self :: getVersionConstraint ( '==' , '1.0' ));
2020-11-12 16:05:50 +00:00
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageA ],
[ 'job' => 'markAliasInstalled' , 'package' => $packageAAlias ],
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'markAliasInstalled' , 'package' => $packageBAlias ],
[ 'job' => 'install' , 'package' => $packageC ],
[ 'job' => 'markAliasInstalled' , 'package' => $packageCAlias ],
]);
2020-11-12 16:05:50 +00:00
}
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
/**
* Tests for a bug introduced in commit 451 bab1c2cd58e05af6e21639b829408ad023463 Solver . php line 554 / 523
*
* Every package and link in this test matters , only a combination this complex will run into the situation in which
* a negatively decided literal will need to be learned inverted as a positive assertion .
*
* In particular in this case the goal is to first have the solver decide X 2.0 should not be installed to later
* decide to learn that X 2.0 must be installed and revert decisions to retry solving with this new assumption .
*/
2022-02-18 09:38:54 +00:00
public function testLearnPositiveLiteral () : void
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
{
2022-11-24 13:39:08 +00:00
$this -> repo -> addPackage ( $packageA = self :: getPackage ( 'A' , '1.0' ));
$this -> repo -> addPackage ( $packageB = self :: getPackage ( 'B' , '1.0' ));
$this -> repo -> addPackage ( $packageC1 = self :: getPackage ( 'C' , '1.0' ));
$this -> repo -> addPackage ( $packageC2 = self :: getPackage ( 'C' , '2.0' ));
$this -> repo -> addPackage ( $packageD = self :: getPackage ( 'D' , '1.0' ));
$this -> repo -> addPackage ( $packageE = self :: getPackage ( 'E' , '1.0' ));
$this -> repo -> addPackage ( $packageF1 = self :: getPackage ( 'F' , '1.0' ));
$this -> repo -> addPackage ( $packageF2 = self :: getPackage ( 'F' , '2.0' ));
$this -> repo -> addPackage ( $packageG1 = self :: getPackage ( 'G' , '1.0' ));
$this -> repo -> addPackage ( $packageG2 = self :: getPackage ( 'G' , '2.0' ));
$this -> repo -> addPackage ( $packageG3 = self :: getPackage ( 'G' , '3.0' ));
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2022-08-17 12:20:07 +00:00
$packageA -> setRequires ([
2022-11-24 13:39:08 +00:00
'b' => new Link ( 'A' , 'B' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE ),
'c' => new Link ( 'A' , 'C' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
'd' => new Link ( 'A' , 'D' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2022-08-17 12:20:07 +00:00
$packageB -> setRequires ([
2022-11-24 13:39:08 +00:00
'e' => new Link ( 'B' , 'E' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2022-08-17 12:20:07 +00:00
$packageC1 -> setRequires ([
2022-11-24 13:39:08 +00:00
'f' => new Link ( 'C' , 'F' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
$packageC2 -> setRequires ([
2022-11-24 13:39:08 +00:00
'f' => new Link ( 'C' , 'F' , self :: getVersionConstraint ( '==' , '1.0' ), Link :: TYPE_REQUIRE ),
'g' => new Link ( 'C' , 'G' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2022-08-17 12:20:07 +00:00
$packageD -> setRequires ([
2022-11-24 13:39:08 +00:00
'f' => new Link ( 'D' , 'F' , self :: getVersionConstraint ( '>=' , '1.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2022-08-17 12:20:07 +00:00
$packageE -> setRequires ([
2022-11-24 13:39:08 +00:00
'g' => new Link ( 'E' , 'G' , self :: getVersionConstraint ( '<=' , '2.0' ), Link :: TYPE_REQUIRE ),
2022-08-17 12:20:07 +00:00
]);
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
$this -> reposComplete ();
2020-01-19 22:28:00 +00:00
$this -> request -> requireName ( 'A' );
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
2019-02-18 11:35:24 +00:00
$this -> createSolver ();
2019-02-10 19:26:47 +00:00
// check correct setup for assertion later
$this -> assertFalse ( $this -> solver -> testFlagLearnedPositiveLiteral );
2022-08-17 12:20:07 +00:00
$this -> checkSolverResult ([
[ 'job' => 'install' , 'package' => $packageF1 ],
[ 'job' => 'install' , 'package' => $packageD ],
[ 'job' => 'install' , 'package' => $packageG2 ],
[ 'job' => 'install' , 'package' => $packageC2 ],
[ 'job' => 'install' , 'package' => $packageE ],
[ 'job' => 'install' , 'package' => $packageB ],
[ 'job' => 'install' , 'package' => $packageA ],
]);
2019-02-10 19:26:47 +00:00
// verify that the code path leading to a negative literal resulting in a positive learned literal is actually
// executed
$this -> assertTrue ( $this -> solver -> testFlagLearnedPositiveLiteral );
Fix solver problem exceptions with unexpected contradictory "Conclusions"
This 5 character fix comes with a solver test as well as a functional
installer test essentially verifying the same thing. The solver test is
more useful when working on the solver. But the functional test is less
likely to be accidentally modified incorrectly during refactoring, as
every single package, version and link in the rather complex test
scenario is essential, and a modified version of the test may very well
still result in a successful installation but no longer verify the bug
described below.
Background:
In commit 451bab1c2cd58e05af6e21639b829408ad023463 from May 19, 2012 I
refactored literals from complex objects into pure integers to reduce
memory consumption. The absolute value of an integer literal is the id
of the package it refers to in the package pool. The sign indicates
whether the package should be installed (positive) or removed (negative),
So a major part of the refactoring was swapping this call:
$literal->getPackageId()
For this:
abs($literal)
Unintentionally in line 554/523 I incorrectly applied this change to the
line:
$this->literalFromId(-$literal->getPackageId());
It was converted to:
-abs($literal);
The function literalFromId used to create a new literal object. By using
the abs() function this change essentially forces the resulting literal
to be negative, while the minus sign previously inverted the literal, so
positive into negative and vice versa.
This particular line is in a function meant to analyze a conflicting
decision during dependency resolution and to draw a conclusion from it,
then revert the state of the solver to an earlier position, and attempt
to solve the rest of the rules again with this new "learned" conclusion.
Because of this bug these conclusions could only ever occur in the
negative, e.g. "don't install package X". This is by far the most likely
scenario when the solver reaches this particular line, but there are
exceptions.
If you experienced a solver problem description that contained a
statement like "Conclusion: don't install vendor/package 1.2.3" which
directly contradicted other statements listed as part of the problem,
this could likely have been the cause.
2019-02-03 00:53:17 +00:00
}
2022-02-18 09:38:54 +00:00
protected function reposComplete () : void
2011-08-05 08:08:21 +00:00
{
2018-09-10 13:23:40 +00:00
$this -> repoSet -> addRepository ( $this -> repo );
2018-09-13 13:23:05 +00:00
$this -> repoSet -> addRepository ( $this -> repoLocked );
2018-09-12 09:49:09 +00:00
}
2018-09-11 13:49:08 +00:00
2022-02-18 09:38:54 +00:00
protected function createSolver () : void
2018-09-12 09:49:09 +00:00
{
2020-04-01 13:27:51 +00:00
$io = new NullIO ();
$this -> pool = $this -> repoSet -> createPool ( $this -> request , $io );
$this -> solver = new Solver ( $this -> policy , $this -> pool , $io );
2011-08-05 08:08:21 +00:00
}
2021-10-30 08:30:36 +00:00
/**
2022-02-23 15:57:47 +00:00
* @ param array < array { job : string , package ? : PackageInterface , from ? : PackageInterface , to ? : PackageInterface } > $expected
2021-10-30 08:30:36 +00:00
*/
2022-02-18 09:38:54 +00:00
protected function checkSolverResult ( array $expected ) : void
2011-08-05 08:08:21 +00:00
{
2018-09-12 09:49:09 +00:00
$this -> createSolver ();
2011-09-23 23:29:22 +00:00
$transaction = $this -> solver -> solve ( $this -> request );
2022-08-17 12:20:07 +00:00
$result = [];
2019-11-07 20:51:53 +00:00
foreach ( $transaction -> getOperations () as $operation ) {
2021-10-16 08:16:06 +00:00
if ( $operation instanceof UpdateOperation ) {
2022-08-17 12:20:07 +00:00
$result [] = [
2017-03-08 14:07:29 +00:00
'job' => 'update' ,
2011-09-25 11:40:12 +00:00
'from' => $operation -> getInitialPackage (),
2017-03-08 14:07:29 +00:00
'to' => $operation -> getTargetPackage (),
2022-08-17 12:20:07 +00:00
];
2021-10-16 08:16:06 +00:00
} elseif ( $operation instanceof MarkAliasInstalledOperation || $operation instanceof MarkAliasUninstalledOperation ) {
2022-08-17 12:20:07 +00:00
$result [] = [
2020-11-12 16:05:50 +00:00
'job' => $operation -> getOperationType (),
'package' => $operation -> getPackage (),
2022-08-17 12:20:07 +00:00
];
2021-10-16 08:16:06 +00:00
} elseif ( $operation instanceof UninstallOperation || $operation instanceof InstallOperation ) {
2020-01-19 22:11:36 +00:00
$job = ( 'uninstall' === $operation -> getOperationType () ? 'remove' : 'install' );
2022-08-17 12:20:07 +00:00
$result [] = [
2017-03-08 14:07:29 +00:00
'job' => $job ,
2015-09-28 09:51:14 +00:00
'package' => $operation -> getPackage (),
2022-08-17 12:20:07 +00:00
];
2021-10-16 08:16:06 +00:00
} else {
throw new \LogicException ( 'Unexpected operation: ' . get_class ( $operation ));
2011-09-23 23:29:22 +00:00
}
2011-08-20 22:19:47 +00:00
}
2022-08-17 12:20:07 +00:00
$expectedReadable = [];
2020-11-12 16:05:50 +00:00
foreach ( $expected as $op ) {
$expectedReadable [] = array_map ( 'strval' , $op );
}
2022-08-17 12:20:07 +00:00
$resultReadable = [];
2020-11-12 16:05:50 +00:00
foreach ( $result as $op ) {
$resultReadable [] = array_map ( 'strval' , $op );
}
$this -> assertEquals ( $expectedReadable , $resultReadable );
2011-05-23 00:23:21 +00:00
$this -> assertEquals ( $expected , $result );
2011-04-05 15:37:19 +00:00
}
}