RuleSetIteratorTest.php 1.8 KB

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