RuleSetIteratorTest.php 1.9 KB

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