RuleSetIteratorTest.php 2.0 KB

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