From 67a88880ec136a3e02f10235a79ba6b04667a7de Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 5 Jun 2020 16:41:37 +0200 Subject: [PATCH] Get rid of EmptyConstraint --- src/Composer/DependencyResolver/Request.php | 4 +- src/Composer/Package/Link.php | 1 - .../Test/Autoload/AutoloadGeneratorTest.php | 88 +++++++++---------- .../Test/DependencyResolver/RequestTest.php | 4 +- .../Test/DependencyResolver/RuleTest.php | 4 +- .../Test/DependencyResolver/SolverTest.php | 10 +-- .../Test/Package/RootAliasPackageTest.php | 12 +-- .../Repository/InstalledRepositoryTest.php | 6 +- .../Composer/Test/Util/PackageSorterTest.php | 3 +- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index 959ba884b..332ead628 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -17,7 +17,7 @@ use Composer\Package\PackageInterface; use Composer\Package\RootAliasPackage; use Composer\Repository\LockArrayRepository; use Composer\Semver\Constraint\ConstraintInterface; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; /** * @author Nils Adermann @@ -56,7 +56,7 @@ class Request public function requireName($packageName, ConstraintInterface $constraint = null) { $packageName = strtolower($packageName); - $this->requires[$packageName] = $constraint ? $constraint : new EmptyConstraint(); + $this->requires[$packageName] = $constraint ? $constraint : new MatchAllConstraint(); } /** diff --git a/src/Composer/Package/Link.php b/src/Composer/Package/Link.php index 16254f68e..81ca86e8b 100644 --- a/src/Composer/Package/Link.php +++ b/src/Composer/Package/Link.php @@ -13,7 +13,6 @@ namespace Composer\Package; use Composer\Semver\Constraint\ConstraintInterface; -use Composer\Semver\Constraint\EmptyConstraint; /** * Represents a link between two packages, represented by their names diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 896221c13..35dcd37da 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -16,7 +16,7 @@ use Composer\Autoload\AutoloadGenerator; use Composer\Package\Link; use Composer\Package\Version\VersionParser; use Composer\Semver\Constraint\Constraint; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Util\Filesystem; use Composer\Package\AliasPackage; use Composer\Package\Package; @@ -367,8 +367,8 @@ class AutoloadGeneratorTest extends TestCase { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), )); $packages = array(); @@ -396,7 +396,7 @@ class AutoloadGeneratorTest extends TestCase { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), )); $packages = array(); @@ -404,11 +404,11 @@ class AutoloadGeneratorTest extends TestCase $packages[] = $b = new Package('b/b', '1.0', '1.0'); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $a->setRequires(array( - new Link('a/a', 'b/b', new EmptyConstraint()), + new Link('a/a', 'b/b', new MatchAllConstraint()), )); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); $b->setRequires(array( - new Link('b/b', 'a/a', new EmptyConstraint()), + new Link('b/b', 'a/a', new MatchAllConstraint()), )); $this->repository->expects($this->once()) @@ -428,13 +428,13 @@ class AutoloadGeneratorTest extends TestCase public function testNonDevAutoloadShouldIncludeReplacedPackages() { $package = new Package('a', '1.0', '1.0'); - $package->setRequires(array(new Link('a', 'a/a', new EmptyConstraint()))); + $package->setRequires(array(new Link('a', 'a/a', new MatchAllConstraint()))); $packages = array(); $packages[] = $a = new Package('a/a', '1.0', '1.0'); $packages[] = $b = new Package('b/b', '1.0', '1.0'); - $a->setRequires(array(new Link('a/a', 'b/c', new EmptyConstraint()))); + $a->setRequires(array(new Link('a/a', 'b/c', new MatchAllConstraint()))); $b->setAutoload(array('psr-4' => array('B\\' => 'src/'))); $b->setReplaces( @@ -463,7 +463,7 @@ class AutoloadGeneratorTest extends TestCase { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), )); $packages = array(); @@ -471,11 +471,11 @@ class AutoloadGeneratorTest extends TestCase $packages[] = $b = new Package('b/b', '1.0', '1.0'); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $a->setRequires(array( - new Link('a/a', 'c/c', new EmptyConstraint()), + new Link('a/a', 'c/c', new MatchAllConstraint()), )); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); $b->setReplaces(array( - new Link('b/b', 'c/c', new EmptyConstraint()), + new Link('b/b', 'c/c', new MatchAllConstraint()), )); $this->repository->expects($this->once()) @@ -496,7 +496,7 @@ class AutoloadGeneratorTest extends TestCase { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()) + new Link('a', 'a/a', new MatchAllConstraint()) )); $packages = array(); @@ -507,18 +507,18 @@ class AutoloadGeneratorTest extends TestCase $packages[] = $e = new Package('e/e', '1.0', '1.0'); $a->setAutoload(array('classmap' => array('src/A.php'))); $a->setRequires(array( - new Link('a/a', 'b/b', new EmptyConstraint()) + new Link('a/a', 'b/b', new MatchAllConstraint()) )); $b->setAutoload(array('classmap' => array('src/B.php'))); $b->setRequires(array( - new Link('b/b', 'e/e', new EmptyConstraint()) + new Link('b/b', 'e/e', new MatchAllConstraint()) )); $c->setAutoload(array('classmap' => array('src/C.php'))); $c->setReplaces(array( - new Link('c/c', 'b/b', new EmptyConstraint()) + new Link('c/c', 'b/b', new MatchAllConstraint()) )); $c->setRequires(array( - new Link('c/c', 'd/d', new EmptyConstraint()) + new Link('c/c', 'd/d', new MatchAllConstraint()) )); $d->setAutoload(array('classmap' => array('src/D.php'))); $e->setAutoload(array('classmap' => array('src/E.php'))); @@ -548,7 +548,7 @@ class AutoloadGeneratorTest extends TestCase { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), )); $package->setAutoload(array( @@ -653,8 +653,8 @@ EOF; { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), )); $packages = array(); @@ -693,8 +693,8 @@ EOF; { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), )); $packages = array(); @@ -733,9 +733,9 @@ EOF; { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), - new Link('a', 'c/c', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), + new Link('a', 'c/c', new MatchAllConstraint()), )); $packages = array(); @@ -778,9 +778,9 @@ EOF; { $package = new Package('a', '1.0', '1.0'); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), - new Link('a', 'c/c', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), + new Link('a', 'c/c', new MatchAllConstraint()), )); $packages = array(); @@ -828,9 +828,9 @@ EOF; $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('files' => array('root.php'))); $package->setRequires(array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), - new Link('a', 'c/c', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), + new Link('a', 'c/c', new MatchAllConstraint()), )); $packages = array(); @@ -879,9 +879,9 @@ EOF; $notAutoloadPackage = new Package('a', '1.0', '1.0'); $requires = array( - new Link('a', 'a/a', new EmptyConstraint()), - new Link('a', 'b/b', new EmptyConstraint()), - new Link('a', 'c/c', new EmptyConstraint()), + new Link('a', 'a/a', new MatchAllConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), + new Link('a', 'c/c', new MatchAllConstraint()), ); $autoloadPackage->setRequires($requires); $notAutoloadPackage->setRequires($requires); @@ -950,10 +950,10 @@ EOF; $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('files' => array('root2.php'))); $package->setRequires(array( - new Link('a', 'z/foo', new EmptyConstraint()), - new Link('a', 'b/bar', new EmptyConstraint()), - new Link('a', 'd/d', new EmptyConstraint()), - new Link('a', 'e/e', new EmptyConstraint()), + new Link('a', 'z/foo', new MatchAllConstraint()), + new Link('a', 'b/bar', new MatchAllConstraint()), + new Link('a', 'd/d', new MatchAllConstraint()), + new Link('a', 'e/e', new MatchAllConstraint()), )); $packages = array(); @@ -964,18 +964,18 @@ EOF; $packages[] = $e = new Package('e/e', '1.0', '1.0'); $z->setAutoload(array('files' => array('testA.php'))); - $z->setRequires(array(new Link('z/foo', 'c/lorem', new EmptyConstraint()))); + $z->setRequires(array(new Link('z/foo', 'c/lorem', new MatchAllConstraint()))); $b->setAutoload(array('files' => array('testB.php'))); - $b->setRequires(array(new Link('b/bar', 'c/lorem', new EmptyConstraint()), new Link('b/bar', 'd/d', new EmptyConstraint()))); + $b->setRequires(array(new Link('b/bar', 'c/lorem', new MatchAllConstraint()), new Link('b/bar', 'd/d', new MatchAllConstraint()))); $c->setAutoload(array('files' => array('testC.php'))); $d->setAutoload(array('files' => array('testD.php'))); - $d->setRequires(array(new Link('d/d', 'c/lorem', new EmptyConstraint()))); + $d->setRequires(array(new Link('d/d', 'c/lorem', new MatchAllConstraint()))); $e->setAutoload(array('files' => array('testE.php'))); - $e->setRequires(array(new Link('e/e', 'c/lorem', new EmptyConstraint()))); + $e->setRequires(array(new Link('e/e', 'c/lorem', new MatchAllConstraint()))); $this->repository->expects($this->once()) ->method('getCanonicalPackages') @@ -1023,8 +1023,8 @@ EOF; 'classmap' => array($this->workingDir.'/src'), )); $mainPackage->setRequires(array( - new Link('z', 'a/a', new EmptyConstraint()), - new Link('z', 'b/b', new EmptyConstraint()), + new Link('z', 'a/a', new MatchAllConstraint()), + new Link('z', 'b/b', new MatchAllConstraint()), )); $packages = array(); @@ -1286,7 +1286,7 @@ EOF; 'files' => array('test.php'), )); $package->setRequires(array( - new Link('a', 'b/b', new EmptyConstraint()), + new Link('a', 'b/b', new MatchAllConstraint()), )); $vendorPackage = new Package('b/b', '1.0', '1.0'); diff --git a/tests/Composer/Test/DependencyResolver/RequestTest.php b/tests/Composer/Test/DependencyResolver/RequestTest.php index 77955597a..a93bc404b 100644 --- a/tests/Composer/Test/DependencyResolver/RequestTest.php +++ b/tests/Composer/Test/DependencyResolver/RequestTest.php @@ -14,7 +14,7 @@ namespace Composer\Test\DependencyResolver; use Composer\DependencyResolver\Request; use Composer\Repository\ArrayRepository; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Test\TestCase; class RequestTest extends TestCase @@ -35,7 +35,7 @@ class RequestTest extends TestCase $this->assertEquals( array( - 'foo' => new EmptyConstraint(), + 'foo' => new MatchAllConstraint(), ), $request->getRequires() ); diff --git a/tests/Composer/Test/DependencyResolver/RuleTest.php b/tests/Composer/Test/DependencyResolver/RuleTest.php index 2608b4946..ebf15fcac 100644 --- a/tests/Composer/Test/DependencyResolver/RuleTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleTest.php @@ -19,7 +19,7 @@ use Composer\DependencyResolver\Pool; use Composer\Package\BasePackage; use Composer\Package\Link; use Composer\Repository\ArrayRepository; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Test\TestCase; class RuleTest extends TestCase @@ -103,7 +103,7 @@ class RuleTest extends TestCase $repositorySetMock = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock(); $requestMock = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); - $emptyConstraint = new EmptyConstraint(); + $emptyConstraint = new MatchAllConstraint(); $emptyConstraint->setPrettyString('*'); $rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_PACKAGE_REQUIRES, new Link('baz', 'foo', $emptyConstraint)); diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index a8f91910d..6ed4c6bbd 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -235,8 +235,8 @@ class SolverTest extends TestCase $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); - $packageA->setRequires(array('b' => new Link('A', 'B', new EmptyConstraint(), 'requires'))); - $newPackageA->setRequires(array('b' => new Link('A', 'B', new EmptyConstraint(), 'requires'))); + $packageA->setRequires(array('b' => new Link('A', 'B', new MatchAllConstraint(), 'requires'))); + $newPackageA->setRequires(array('b' => new Link('A', 'B', new MatchAllConstraint(), 'requires'))); $this->reposComplete(); @@ -639,7 +639,7 @@ class SolverTest extends TestCase $this->reposComplete(); - $emptyConstraint = new EmptyConstraint(); + $emptyConstraint = new MatchAllConstraint(); $emptyConstraint->setPrettyString('*'); $this->request->requireName('A', $emptyConstraint); @@ -686,7 +686,7 @@ class SolverTest extends TestCase $msg = "\n"; $msg .= " Problem 1\n"; - $msg .= " - Root composer.json requires a [] -> satisfiable by A[1.0].\n"; + $msg .= " - Root composer.json requires a * -> satisfiable by A[1.0].\n"; $msg .= " - A 1.0 requires b >= 2.0 -> found B[1.0] but it does not match the constraint.\n"; $this->assertEquals($msg, $e->getPrettyString($this->repoSet, $this->request, $this->pool, false)); } @@ -715,7 +715,7 @@ class SolverTest extends TestCase $this->reposComplete(); - $emptyConstraint = new EmptyConstraint(); + $emptyConstraint = new MatchAllConstraint(); $emptyConstraint->setPrettyString('*'); $this->request->requireName('A', $emptyConstraint); diff --git a/tests/Composer/Test/Package/RootAliasPackageTest.php b/tests/Composer/Test/Package/RootAliasPackageTest.php index 5cfcd7179..459f935e5 100644 --- a/tests/Composer/Test/Package/RootAliasPackageTest.php +++ b/tests/Composer/Test/Package/RootAliasPackageTest.php @@ -14,7 +14,7 @@ namespace Composer\Test\Package; use Composer\Package\Link; use Composer\Package\RootAliasPackage; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Test\TestCase; use Prophecy\Argument; @@ -27,7 +27,7 @@ class RootAliasPackageTest extends TestCase $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $this->assertEmpty($alias->getRequires()); - $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version')); + $links = array(new Link('a', 'b', new MatchAllConstraint(), 'foo', 'self.version')); $alias->setRequires($links); $this->assertNotEmpty($alias->getRequires()); } @@ -39,7 +39,7 @@ class RootAliasPackageTest extends TestCase $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $this->assertEmpty($alias->getDevRequires()); - $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version')); + $links = array(new Link('a', 'b', new MatchAllConstraint(), 'foo', 'self.version')); $alias->setDevRequires($links); $this->assertNotEmpty($alias->getDevRequires()); } @@ -51,7 +51,7 @@ class RootAliasPackageTest extends TestCase $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $this->assertEmpty($alias->getConflicts()); - $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version')); + $links = array(new Link('a', 'b', new MatchAllConstraint(), 'foo', 'self.version')); $alias->setConflicts($links); $this->assertNotEmpty($alias->getConflicts()); } @@ -63,7 +63,7 @@ class RootAliasPackageTest extends TestCase $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $this->assertEmpty($alias->getProvides()); - $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version')); + $links = array(new Link('a', 'b', new MatchAllConstraint(), 'foo', 'self.version')); $alias->setProvides($links); $this->assertNotEmpty($alias->getProvides()); } @@ -75,7 +75,7 @@ class RootAliasPackageTest extends TestCase $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $this->assertEmpty($alias->getReplaces()); - $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version')); + $links = array(new Link('a', 'b', new MatchAllConstraint(), 'foo', 'self.version')); $alias->setReplaces($links); $this->assertNotEmpty($alias->getReplaces()); } diff --git a/tests/Composer/Test/Repository/InstalledRepositoryTest.php b/tests/Composer/Test/Repository/InstalledRepositoryTest.php index 4c63f0670..505278c3b 100644 --- a/tests/Composer/Test/Repository/InstalledRepositoryTest.php +++ b/tests/Composer/Test/Repository/InstalledRepositoryTest.php @@ -16,7 +16,7 @@ use Composer\Repository\InstalledRepository; use Composer\Repository\ArrayRepository; use Composer\Repository\InstalledArrayRepository; use Composer\Package\Link; -use Composer\Semver\Constraint\EmptyConstraint; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Test\TestCase; class InstalledRepositoryTest extends TestCase @@ -31,8 +31,8 @@ class InstalledRepositoryTest extends TestCase $arrayRepoTwo->addPackage($bar = $this->getPackage('bar', '1')); $arrayRepoTwo->addPackage($bar2 = $this->getPackage('bar', '2')); - $foo->setReplaces(array(new Link('foo', 'provided', new EmptyConstraint()))); - $bar2->setProvides(array(new Link('bar', 'provided', new EmptyConstraint()))); + $foo->setReplaces(array(new Link('foo', 'provided', new MatchAllConstraint()))); + $bar2->setProvides(array(new Link('bar', 'provided', new MatchAllConstraint()))); $repo = new InstalledRepository(array($arrayRepoOne, $arrayRepoTwo)); diff --git a/tests/Composer/Test/Util/PackageSorterTest.php b/tests/Composer/Test/Util/PackageSorterTest.php index e93503436..8704a3af0 100644 --- a/tests/Composer/Test/Util/PackageSorterTest.php +++ b/tests/Composer/Test/Util/PackageSorterTest.php @@ -16,6 +16,7 @@ use Composer\Package\Link; use Composer\Package\Package; use Composer\Test\TestCase; use Composer\Util\PackageSorter; +use Composer\Semver\Constraint\MatchAllConstraint; class PackageSorterTest extends TestCase { @@ -120,7 +121,7 @@ class PackageSorterTest extends TestCase $links = array(); foreach ($requires as $requireName) { - $links[] = new Link($package->getName(), $requireName); + $links[] = new Link($package->getName(), $requireName, new MatchAllConstraint); } $package->setRequires($links);