RuleSetIteratorTest.php 1.9 KB

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