RuleTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\DependencyResolver;
  12. use Composer\DependencyResolver\Rule;
  13. use Composer\DependencyResolver\RuleSet;
  14. use Composer\DependencyResolver\Pool;
  15. use Composer\Repository\ArrayRepository;
  16. use Composer\TestCase;
  17. class RuleTest extends TestCase
  18. {
  19. protected $pool;
  20. public function setUp()
  21. {
  22. $this->pool = new Pool;
  23. }
  24. public function testGetHash()
  25. {
  26. $rule = new Rule(array(123), Rule::RULE_JOB_INSTALL, null);
  27. $hash = unpack('ihash', md5('123', true));
  28. $this->assertEquals($hash['hash'], $rule->getHash());
  29. }
  30. public function testEqualsForRulesWithDifferentHashes()
  31. {
  32. $rule = new Rule(array(1, 2), Rule::RULE_JOB_INSTALL, null);
  33. $rule2 = new Rule(array(1, 3), Rule::RULE_JOB_INSTALL, null);
  34. $this->assertFalse($rule->equals($rule2));
  35. }
  36. public function testEqualsForRulesWithDifferLiteralsQuantity()
  37. {
  38. $rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
  39. $rule2 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
  40. $this->assertFalse($rule->equals($rule2));
  41. }
  42. public function testEqualsForRulesWithSameLiterals()
  43. {
  44. $rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
  45. $rule2 = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
  46. $this->assertTrue($rule->equals($rule2));
  47. }
  48. public function testSetAndGetType()
  49. {
  50. $rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
  51. $rule->setType(RuleSet::TYPE_JOB);
  52. $this->assertEquals(RuleSet::TYPE_JOB, $rule->getType());
  53. }
  54. public function testEnable()
  55. {
  56. $rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
  57. $rule->disable();
  58. $rule->enable();
  59. $this->assertTrue($rule->isEnabled());
  60. $this->assertFalse($rule->isDisabled());
  61. }
  62. public function testDisable()
  63. {
  64. $rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
  65. $rule->enable();
  66. $rule->disable();
  67. $this->assertTrue($rule->isDisabled());
  68. $this->assertFalse($rule->isEnabled());
  69. }
  70. public function testIsAssertions()
  71. {
  72. $rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
  73. $rule2 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
  74. $this->assertFalse($rule->isAssertion());
  75. $this->assertTrue($rule2->isAssertion());
  76. }
  77. public function testPrettyString()
  78. {
  79. $repo = new ArrayRepository;
  80. $repo->addPackage($p1 = $this->getPackage('foo', '2.1'));
  81. $repo->addPackage($p2 = $this->getPackage('baz', '1.1'));
  82. $this->pool->addRepository($repo);
  83. $rule = new Rule(array($p1->getId(), -$p2->getId()), Rule::RULE_JOB_INSTALL, null);
  84. $this->assertEquals('Install command rule (don\'t install baz 1.1|install foo 2.1)', $rule->getPrettyString($this->pool));
  85. }
  86. }