2012-01-22 21:06:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\DependencyResolver;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
use Composer\DependencyResolver\GenericRule;
|
2012-01-22 21:06:09 +00:00
|
|
|
use Composer\DependencyResolver\Rule;
|
2015-07-09 15:21:45 +00:00
|
|
|
use Composer\DependencyResolver\RuleSet;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\DependencyResolver\Pool;
|
2018-09-11 11:33:29 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2020-01-19 22:11:36 +00:00
|
|
|
use Composer\Package\Link;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\Repository\ArrayRepository;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
class RuleTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testGetHash()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(123), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2015-07-08 17:36:13 +00:00
|
|
|
$hash = unpack('ihash', md5('123', true));
|
|
|
|
$this->assertEquals($hash['hash'], $rule->getHash());
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEqualsForRulesWithDifferentHashes()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(1, 2), Rule::RULE_ROOT_REQUIRE, null);
|
|
|
|
$rule2 = new GenericRule(array(1, 3), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertFalse($rule->equals($rule2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEqualsForRulesWithDifferLiteralsQuantity()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(1, 12), Rule::RULE_ROOT_REQUIRE, null);
|
|
|
|
$rule2 = new GenericRule(array(1), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertFalse($rule->equals($rule2));
|
|
|
|
}
|
|
|
|
|
2012-05-20 13:57:38 +00:00
|
|
|
public function testEqualsForRulesWithSameLiterals()
|
2012-01-22 21:06:09 +00:00
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(1, 12), Rule::RULE_ROOT_REQUIRE, null);
|
|
|
|
$rule2 = new GenericRule(array(1, 12), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertTrue($rule->equals($rule2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetAndGetType()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null);
|
|
|
|
$rule->setType(RuleSet::TYPE_REQUEST);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2020-01-19 22:11:36 +00:00
|
|
|
$this->assertEquals(RuleSet::TYPE_REQUEST, $rule->getType());
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnable()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->disable();
|
|
|
|
$rule->enable();
|
|
|
|
|
|
|
|
$this->assertTrue($rule->isEnabled());
|
|
|
|
$this->assertFalse($rule->isDisabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisable()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->enable();
|
|
|
|
$rule->disable();
|
|
|
|
|
|
|
|
$this->assertTrue($rule->isDisabled());
|
|
|
|
$this->assertFalse($rule->isEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsAssertions()
|
|
|
|
{
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array(1, 12), Rule::RULE_ROOT_REQUIRE, null);
|
|
|
|
$rule2 = new GenericRule(array(1), Rule::RULE_ROOT_REQUIRE, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertFalse($rule->isAssertion());
|
|
|
|
$this->assertTrue($rule2->isAssertion());
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:02:50 +00:00
|
|
|
public function testPrettyString()
|
2012-01-22 21:06:09 +00:00
|
|
|
{
|
2020-01-17 14:48:31 +00:00
|
|
|
$pool = new Pool(array(
|
2018-09-12 09:49:09 +00:00
|
|
|
$p1 = $this->getPackage('foo', '2.1'),
|
|
|
|
$p2 = $this->getPackage('baz', '1.1'),
|
|
|
|
));
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2020-01-29 21:47:16 +00:00
|
|
|
$repositorySetMock = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
|
|
|
|
$requestMock = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
|
|
|
|
|
2020-01-19 22:11:36 +00:00
|
|
|
$rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_PACKAGE_REQUIRES, new Link('baz', 'foo'));
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2020-01-30 14:23:22 +00:00
|
|
|
$this->assertEquals('baz 1.1 relates to foo -> satisfiable by foo[2.1].', $rule->getPrettyString($repositorySetMock, $requestMock, $pool));
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
}
|