RuleSetIteratorTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\GenericRule;
  13. use Composer\DependencyResolver\Rule;
  14. use Composer\DependencyResolver\RuleSet;
  15. use Composer\DependencyResolver\RuleSetIterator;
  16. use Composer\DependencyResolver\Pool;
  17. use Composer\Package\BasePackage;
  18. use Composer\Test\TestCase;
  19. class RuleSetIteratorTest extends TestCase
  20. {
  21. protected $rules;
  22. protected $pool;
  23. protected function setUp()
  24. {
  25. $this->pool = new Pool();
  26. $this->rules = array(
  27. RuleSet::TYPE_REQUEST => array(
  28. new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null),
  29. new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null),
  30. ),
  31. RuleSet::TYPE_LEARNED => array(
  32. new GenericRule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
  33. ),
  34. RuleSet::TYPE_PACKAGE => array(),
  35. );
  36. }
  37. public function testForeach()
  38. {
  39. $ruleSetIterator = new RuleSetIterator($this->rules);
  40. $result = array();
  41. foreach ($ruleSetIterator as $rule) {
  42. $result[] = $rule;
  43. }
  44. $expected = array(
  45. $this->rules[RuleSet::TYPE_REQUEST][0],
  46. $this->rules[RuleSet::TYPE_REQUEST][1],
  47. $this->rules[RuleSet::TYPE_LEARNED][0],
  48. );
  49. $this->assertEquals($expected, $result);
  50. }
  51. public function testKeys()
  52. {
  53. $ruleSetIterator = new RuleSetIterator($this->rules);
  54. $result = array();
  55. foreach ($ruleSetIterator as $key => $rule) {
  56. $result[] = $key;
  57. }
  58. $expected = array(
  59. RuleSet::TYPE_REQUEST,
  60. RuleSet::TYPE_REQUEST,
  61. RuleSet::TYPE_LEARNED,
  62. );
  63. $this->assertEquals($expected, $result);
  64. }
  65. }