2011-06-26 22:11:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\DependencyResolver;
|
|
|
|
|
|
|
|
use Composer\DependencyResolver\Rule;
|
|
|
|
use Composer\DependencyResolver\RuleSet;
|
|
|
|
use Composer\DependencyResolver\RuleSetIterator;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\DependencyResolver\Pool;
|
2011-06-26 22:11:57 +00:00
|
|
|
|
2013-02-20 14:27:11 +00:00
|
|
|
class RuleSetIteratorTest extends \PHPUnit_Framework_TestCase
|
2011-06-26 22:11:57 +00:00
|
|
|
{
|
|
|
|
protected $rules;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2012-05-19 18:38:56 +00:00
|
|
|
$this->pool = new Pool;
|
|
|
|
|
2011-06-26 22:11:57 +00:00
|
|
|
$this->rules = array(
|
|
|
|
RuleSet::TYPE_JOB => array(
|
2014-12-01 18:02:50 +00:00
|
|
|
new Rule(array(), 'job1', null),
|
|
|
|
new Rule(array(), 'job2', null),
|
2011-06-26 22:11:57 +00:00
|
|
|
),
|
2012-04-27 16:28:18 +00:00
|
|
|
RuleSet::TYPE_LEARNED => array(
|
2014-12-01 18:02:50 +00:00
|
|
|
new Rule(array(), 'update1', null),
|
2011-06-26 22:11:57 +00:00
|
|
|
),
|
|
|
|
RuleSet::TYPE_PACKAGE => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForeach()
|
|
|
|
{
|
|
|
|
$ruleSetIterator = new RuleSetIterator($this->rules);
|
|
|
|
|
|
|
|
$result = array();
|
2012-01-23 08:21:36 +00:00
|
|
|
foreach ($ruleSetIterator as $rule) {
|
2011-06-26 22:11:57 +00:00
|
|
|
$result[] = $rule;
|
|
|
|
}
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
$this->rules[RuleSet::TYPE_JOB][0],
|
|
|
|
$this->rules[RuleSet::TYPE_JOB][1],
|
2012-04-27 16:28:18 +00:00
|
|
|
$this->rules[RuleSet::TYPE_LEARNED][0],
|
2011-06-26 22:11:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
public function testKeys()
|
|
|
|
{
|
|
|
|
$ruleSetIterator = new RuleSetIterator($this->rules);
|
|
|
|
|
|
|
|
$result = array();
|
2012-01-23 08:21:36 +00:00
|
|
|
foreach ($ruleSetIterator as $key => $rule) {
|
2012-01-22 21:06:09 +00:00
|
|
|
$result[] = $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
RuleSet::TYPE_JOB,
|
|
|
|
RuleSet::TYPE_JOB,
|
2012-04-27 16:28:18 +00:00
|
|
|
RuleSet::TYPE_LEARNED,
|
2012-01-22 21:06:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2011-06-26 22:11:57 +00:00
|
|
|
}
|