RuleSetIteratorTest.php 2.0 KB

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