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;
|
|
|
|
|
|
|
|
use Composer\DependencyResolver\Rule;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\DependencyResolver\Pool;
|
|
|
|
use Composer\Repository\ArrayRepository;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
class RuleTest extends TestCase
|
|
|
|
{
|
2012-05-19 18:38:56 +00:00
|
|
|
protected $pool;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->pool = new Pool;
|
|
|
|
}
|
|
|
|
|
2012-01-22 21:06:09 +00:00
|
|
|
public function testGetHash()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(123), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2012-05-20 13:57:38 +00:00
|
|
|
$this->assertEquals(substr(md5('123'), 0, 5), $rule->getHash());
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetAndGetId()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->setId(666);
|
|
|
|
|
|
|
|
$this->assertEquals(666, $rule->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEqualsForRulesWithDifferentHashes()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(1, 2), 'job1', null);
|
|
|
|
$rule2 = new Rule(array(1, 3), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertFalse($rule->equals($rule2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEqualsForRulesWithDifferLiteralsQuantity()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(1, 12), 'job1', null);
|
|
|
|
$rule2 = new Rule(array(1), 'job1', 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
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(1, 12), 'job1', null);
|
|
|
|
$rule2 = new Rule(array(1, 12), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertTrue($rule->equals($rule2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetAndGetType()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->setType('someType');
|
|
|
|
|
|
|
|
$this->assertEquals('someType', $rule->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnable()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->disable();
|
|
|
|
$rule->enable();
|
|
|
|
|
|
|
|
$this->assertTrue($rule->isEnabled());
|
|
|
|
$this->assertFalse($rule->isDisabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisable()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$rule->enable();
|
|
|
|
$rule->disable();
|
|
|
|
|
|
|
|
$this->assertTrue($rule->isDisabled());
|
|
|
|
$this->assertFalse($rule->isEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsAssertions()
|
|
|
|
{
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array(1, 12), 'job1', null);
|
|
|
|
$rule2 = new Rule(array(1), 'job1', 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
|
|
|
{
|
2012-05-19 18:38:56 +00:00
|
|
|
$repo = new ArrayRepository;
|
|
|
|
$repo->addPackage($p1 = $this->getPackage('foo', '2.1'));
|
|
|
|
$repo->addPackage($p2 = $this->getPackage('baz', '1.1'));
|
|
|
|
$this->pool->addRepository($repo);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2014-12-01 18:02:50 +00:00
|
|
|
$rule = new Rule(array($p1->getId(), -$p2->getId()), 'job1', null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2014-12-01 18:02:50 +00:00
|
|
|
$this->assertEquals('(don\'t install baz 1.1|install foo 2.1)', $rule->getPrettyString($this->pool));
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
}
|