1
0
Fork 0

Made the constraint argument in Link mandatory

pull/8850/head
Yanick Witschi 2020-05-01 20:32:17 +02:00 committed by Jordi Boggiano
parent 63906171f0
commit bde9502473
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
6 changed files with 59 additions and 55 deletions

View File

@ -56,11 +56,11 @@ class Link
* @param string $description Used to create a descriptive string representation * @param string $description Used to create a descriptive string representation
* @param string|null $prettyConstraint * @param string|null $prettyConstraint
*/ */
public function __construct($source, $target, ConstraintInterface $constraint = null, $description = 'relates to', $prettyConstraint = null) public function __construct($source, $target, ConstraintInterface $constraint, $description = 'relates to', $prettyConstraint = null)
{ {
$this->source = strtolower($source); $this->source = strtolower($source);
$this->target = strtolower($target); $this->target = strtolower($target);
$this->constraint = $constraint ? $constraint : new EmptyConstraint(); $this->constraint = $constraint;
$this->description = $description; $this->description = $description;
$this->prettyConstraint = $prettyConstraint; $this->prettyConstraint = $prettyConstraint;
} }

View File

@ -16,6 +16,7 @@ use Composer\Autoload\AutoloadGenerator;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Semver\Constraint\EmptyConstraint;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\Package; use Composer\Package\Package;
@ -366,8 +367,8 @@ class AutoloadGeneratorTest extends TestCase
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -395,7 +396,7 @@ class AutoloadGeneratorTest extends TestCase
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -403,11 +404,11 @@ class AutoloadGeneratorTest extends TestCase
$packages[] = $b = new Package('b/b', '1.0', '1.0'); $packages[] = $b = new Package('b/b', '1.0', '1.0');
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
$a->setRequires(array( $a->setRequires(array(
new Link('a/a', 'b/b'), new Link('a/a', 'b/b', new EmptyConstraint()),
)); ));
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
$b->setRequires(array( $b->setRequires(array(
new Link('b/b', 'a/a'), new Link('b/b', 'a/a', new EmptyConstraint()),
)); ));
$this->repository->expects($this->once()) $this->repository->expects($this->once())
@ -427,13 +428,13 @@ class AutoloadGeneratorTest extends TestCase
public function testNonDevAutoloadShouldIncludeReplacedPackages() public function testNonDevAutoloadShouldIncludeReplacedPackages()
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array(new Link('a', 'a/a'))); $package->setRequires(array(new Link('a', 'a/a', new EmptyConstraint())));
$packages = array(); $packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0'); $packages[] = $a = new Package('a/a', '1.0', '1.0');
$packages[] = $b = new Package('b/b', '1.0', '1.0'); $packages[] = $b = new Package('b/b', '1.0', '1.0');
$a->setRequires(array(new Link('a/a', 'b/c'))); $a->setRequires(array(new Link('a/a', 'b/c', new EmptyConstraint())));
$b->setAutoload(array('psr-4' => array('B\\' => 'src/'))); $b->setAutoload(array('psr-4' => array('B\\' => 'src/')));
$b->setReplaces( $b->setReplaces(
@ -462,7 +463,7 @@ class AutoloadGeneratorTest extends TestCase
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -470,11 +471,11 @@ class AutoloadGeneratorTest extends TestCase
$packages[] = $b = new Package('b/b', '1.0', '1.0'); $packages[] = $b = new Package('b/b', '1.0', '1.0');
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
$a->setRequires(array( $a->setRequires(array(
new Link('a/a', 'c/c'), new Link('a/a', 'c/c', new EmptyConstraint()),
)); ));
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
$b->setReplaces(array( $b->setReplaces(array(
new Link('b/b', 'c/c'), new Link('b/b', 'c/c', new EmptyConstraint()),
)); ));
$this->repository->expects($this->once()) $this->repository->expects($this->once())
@ -495,7 +496,7 @@ class AutoloadGeneratorTest extends TestCase
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a') new Link('a', 'a/a', new EmptyConstraint())
)); ));
$packages = array(); $packages = array();
@ -506,18 +507,18 @@ class AutoloadGeneratorTest extends TestCase
$packages[] = $e = new Package('e/e', '1.0', '1.0'); $packages[] = $e = new Package('e/e', '1.0', '1.0');
$a->setAutoload(array('classmap' => array('src/A.php'))); $a->setAutoload(array('classmap' => array('src/A.php')));
$a->setRequires(array( $a->setRequires(array(
new Link('a/a', 'b/b') new Link('a/a', 'b/b', new EmptyConstraint())
)); ));
$b->setAutoload(array('classmap' => array('src/B.php'))); $b->setAutoload(array('classmap' => array('src/B.php')));
$b->setRequires(array( $b->setRequires(array(
new Link('b/b', 'e/e') new Link('b/b', 'e/e', new EmptyConstraint())
)); ));
$c->setAutoload(array('classmap' => array('src/C.php'))); $c->setAutoload(array('classmap' => array('src/C.php')));
$c->setReplaces(array( $c->setReplaces(array(
new Link('c/c', 'b/b') new Link('c/c', 'b/b', new EmptyConstraint())
)); ));
$c->setRequires(array( $c->setRequires(array(
new Link('c/c', 'd/d') new Link('c/c', 'd/d', new EmptyConstraint())
)); ));
$d->setAutoload(array('classmap' => array('src/D.php'))); $d->setAutoload(array('classmap' => array('src/D.php')));
$e->setAutoload(array('classmap' => array('src/E.php'))); $e->setAutoload(array('classmap' => array('src/E.php')));
@ -547,7 +548,7 @@ class AutoloadGeneratorTest extends TestCase
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
)); ));
$package->setAutoload(array( $package->setAutoload(array(
@ -652,8 +653,8 @@ EOF;
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -692,8 +693,8 @@ EOF;
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -732,9 +733,9 @@ EOF;
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
new Link('a', 'c/c'), new Link('a', 'c/c', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -777,9 +778,9 @@ EOF;
{ {
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
new Link('a', 'c/c'), new Link('a', 'c/c', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -827,9 +828,9 @@ EOF;
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setAutoload(array('files' => array('root.php'))); $package->setAutoload(array('files' => array('root.php')));
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
new Link('a', 'c/c'), new Link('a', 'c/c', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -878,9 +879,9 @@ EOF;
$notAutoloadPackage = new Package('a', '1.0', '1.0'); $notAutoloadPackage = new Package('a', '1.0', '1.0');
$requires = array( $requires = array(
new Link('a', 'a/a'), new Link('a', 'a/a', new EmptyConstraint()),
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
new Link('a', 'c/c'), new Link('a', 'c/c', new EmptyConstraint()),
); );
$autoloadPackage->setRequires($requires); $autoloadPackage->setRequires($requires);
$notAutoloadPackage->setRequires($requires); $notAutoloadPackage->setRequires($requires);
@ -949,10 +950,10 @@ EOF;
$package = new Package('a', '1.0', '1.0'); $package = new Package('a', '1.0', '1.0');
$package->setAutoload(array('files' => array('root2.php'))); $package->setAutoload(array('files' => array('root2.php')));
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'z/foo'), new Link('a', 'z/foo', new EmptyConstraint()),
new Link('a', 'b/bar'), new Link('a', 'b/bar', new EmptyConstraint()),
new Link('a', 'd/d'), new Link('a', 'd/d', new EmptyConstraint()),
new Link('a', 'e/e'), new Link('a', 'e/e', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -963,18 +964,18 @@ EOF;
$packages[] = $e = new Package('e/e', '1.0', '1.0'); $packages[] = $e = new Package('e/e', '1.0', '1.0');
$z->setAutoload(array('files' => array('testA.php'))); $z->setAutoload(array('files' => array('testA.php')));
$z->setRequires(array(new Link('z/foo', 'c/lorem'))); $z->setRequires(array(new Link('z/foo', 'c/lorem', new EmptyConstraint())));
$b->setAutoload(array('files' => array('testB.php'))); $b->setAutoload(array('files' => array('testB.php')));
$b->setRequires(array(new Link('b/bar', 'c/lorem'), new Link('b/bar', 'd/d'))); $b->setRequires(array(new Link('b/bar', 'c/lorem', new EmptyConstraint()), new Link('b/bar', 'd/d', new EmptyConstraint())));
$c->setAutoload(array('files' => array('testC.php'))); $c->setAutoload(array('files' => array('testC.php')));
$d->setAutoload(array('files' => array('testD.php'))); $d->setAutoload(array('files' => array('testD.php')));
$d->setRequires(array(new Link('d/d', 'c/lorem'))); $d->setRequires(array(new Link('d/d', 'c/lorem', new EmptyConstraint())));
$e->setAutoload(array('files' => array('testE.php'))); $e->setAutoload(array('files' => array('testE.php')));
$e->setRequires(array(new Link('e/e', 'c/lorem'))); $e->setRequires(array(new Link('e/e', 'c/lorem', new EmptyConstraint())));
$this->repository->expects($this->once()) $this->repository->expects($this->once())
->method('getCanonicalPackages') ->method('getCanonicalPackages')
@ -1022,8 +1023,8 @@ EOF;
'classmap' => array($this->workingDir.'/src'), 'classmap' => array($this->workingDir.'/src'),
)); ));
$mainPackage->setRequires(array( $mainPackage->setRequires(array(
new Link('z', 'a/a'), new Link('z', 'a/a', new EmptyConstraint()),
new Link('z', 'b/b'), new Link('z', 'b/b', new EmptyConstraint()),
)); ));
$packages = array(); $packages = array();
@ -1285,7 +1286,7 @@ EOF;
'files' => array('test.php'), 'files' => array('test.php'),
)); ));
$package->setRequires(array( $package->setRequires(array(
new Link('a', 'b/b'), new Link('a', 'b/b', new EmptyConstraint()),
)); ));
$vendorPackage = new Package('b/b', '1.0', '1.0'); $vendorPackage = new Package('b/b', '1.0', '1.0');

View File

@ -19,6 +19,7 @@ use Composer\DependencyResolver\Pool;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Semver\Constraint\EmptyConstraint;
use Composer\Test\TestCase; use Composer\Test\TestCase;
class RuleTest extends TestCase class RuleTest extends TestCase
@ -102,7 +103,7 @@ class RuleTest extends TestCase
$repositorySetMock = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock(); $repositorySetMock = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
$requestMock = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); $requestMock = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
$rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_PACKAGE_REQUIRES, new Link('baz', 'foo', 'relates to', '*')); $rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_PACKAGE_REQUIRES, new Link('baz', 'foo', new EmptyConstraint(), 'relates to', '*'));
$this->assertEquals('baz 1.1 relates to foo * -> satisfiable by foo[2.1].', $rule->getPrettyString($repositorySetMock, $requestMock, $pool, false)); $this->assertEquals('baz 1.1 relates to foo * -> satisfiable by foo[2.1].', $rule->getPrettyString($repositorySetMock, $requestMock, $pool, false));
} }

View File

@ -235,8 +235,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1')); $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$packageA->setRequires(array('b' => new Link('A', 'B', null, 'requires'))); $packageA->setRequires(array('b' => new Link('A', 'B', new EmptyConstraint(), 'requires')));
$newPackageA->setRequires(array('b' => new Link('A', 'B', null, 'requires'))); $newPackageA->setRequires(array('b' => new Link('A', 'B', new EmptyConstraint(), 'requires')));
$this->reposComplete(); $this->reposComplete();

View File

@ -14,6 +14,7 @@ namespace Composer\Test\Package;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\RootAliasPackage; use Composer\Package\RootAliasPackage;
use Composer\Semver\Constraint\EmptyConstraint;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
@ -26,7 +27,7 @@ class RootAliasPackageTest extends TestCase
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getRequires()); $this->assertEmpty($alias->getRequires());
$links = array(new Link('a', 'b', null, 'foo', 'self.version')); $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version'));
$alias->setRequires($links); $alias->setRequires($links);
$this->assertNotEmpty($alias->getRequires()); $this->assertNotEmpty($alias->getRequires());
} }
@ -38,7 +39,7 @@ class RootAliasPackageTest extends TestCase
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getDevRequires()); $this->assertEmpty($alias->getDevRequires());
$links = array(new Link('a', 'b', null, 'foo', 'self.version')); $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version'));
$alias->setDevRequires($links); $alias->setDevRequires($links);
$this->assertNotEmpty($alias->getDevRequires()); $this->assertNotEmpty($alias->getDevRequires());
} }
@ -50,7 +51,7 @@ class RootAliasPackageTest extends TestCase
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getConflicts()); $this->assertEmpty($alias->getConflicts());
$links = array(new Link('a', 'b', null, 'foo', 'self.version')); $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version'));
$alias->setConflicts($links); $alias->setConflicts($links);
$this->assertNotEmpty($alias->getConflicts()); $this->assertNotEmpty($alias->getConflicts());
} }
@ -62,7 +63,7 @@ class RootAliasPackageTest extends TestCase
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getProvides()); $this->assertEmpty($alias->getProvides());
$links = array(new Link('a', 'b', null, 'foo', 'self.version')); $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version'));
$alias->setProvides($links); $alias->setProvides($links);
$this->assertNotEmpty($alias->getProvides()); $this->assertNotEmpty($alias->getProvides());
} }
@ -74,7 +75,7 @@ class RootAliasPackageTest extends TestCase
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0'); $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getReplaces()); $this->assertEmpty($alias->getReplaces());
$links = array(new Link('a', 'b', null, 'foo', 'self.version')); $links = array(new Link('a', 'b', new EmptyConstraint(), 'foo', 'self.version'));
$alias->setReplaces($links); $alias->setReplaces($links);
$this->assertNotEmpty($alias->getReplaces()); $this->assertNotEmpty($alias->getReplaces());
} }

View File

@ -16,6 +16,7 @@ use Composer\Repository\InstalledRepository;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Repository\InstalledArrayRepository; use Composer\Repository\InstalledArrayRepository;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Semver\Constraint\EmptyConstraint;
use Composer\Test\TestCase; use Composer\Test\TestCase;
class InstalledRepositoryTest extends TestCase class InstalledRepositoryTest extends TestCase
@ -30,8 +31,8 @@ class InstalledRepositoryTest extends TestCase
$arrayRepoTwo->addPackage($bar = $this->getPackage('bar', '1')); $arrayRepoTwo->addPackage($bar = $this->getPackage('bar', '1'));
$arrayRepoTwo->addPackage($bar2 = $this->getPackage('bar', '2')); $arrayRepoTwo->addPackage($bar2 = $this->getPackage('bar', '2'));
$foo->setReplaces(array(new Link('foo', 'provided'))); $foo->setReplaces(array(new Link('foo', 'provided', new EmptyConstraint())));
$bar2->setProvides(array(new Link('bar', 'provided'))); $bar2->setProvides(array(new Link('bar', 'provided', new EmptyConstraint())));
$repo = new InstalledRepository(array($arrayRepoOne, $arrayRepoTwo)); $repo = new InstalledRepository(array($arrayRepoOne, $arrayRepoTwo));