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;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
use Composer\DependencyResolver\GenericRule;
|
2011-06-26 22:11:57 +00:00
|
|
|
use Composer\DependencyResolver\Rule;
|
|
|
|
use Composer\DependencyResolver\RuleSet;
|
|
|
|
use Composer\DependencyResolver\RuleSetIterator;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\DependencyResolver\Pool;
|
2018-09-11 11:33:29 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2017-11-04 14:52:13 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2011-06-26 22:11:57 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class RuleSetIteratorTest extends TestCase
|
2011-06-26 22:11:57 +00:00
|
|
|
{
|
|
|
|
protected $rules;
|
2018-01-06 14:05:39 +00:00
|
|
|
protected $pool;
|
2011-06-26 22:11:57 +00:00
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2019-11-27 16:55:02 +00:00
|
|
|
$this->pool = new Pool();
|
2012-05-19 18:38:56 +00:00
|
|
|
|
2011-06-26 22:11:57 +00:00
|
|
|
$this->rules = array(
|
2020-01-19 22:11:36 +00:00
|
|
|
RuleSet::TYPE_REQUEST => array(
|
|
|
|
new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null),
|
|
|
|
new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null),
|
2011-06-26 22:11:57 +00:00
|
|
|
),
|
2012-04-27 16:28:18 +00:00
|
|
|
RuleSet::TYPE_LEARNED => array(
|
2017-02-16 22:00:57 +00:00
|
|
|
new GenericRule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, 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(
|
2020-01-19 22:11:36 +00:00
|
|
|
$this->rules[RuleSet::TYPE_REQUEST][0],
|
|
|
|
$this->rules[RuleSet::TYPE_REQUEST][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(
|
2020-01-19 22:11:36 +00:00
|
|
|
RuleSet::TYPE_REQUEST,
|
|
|
|
RuleSet::TYPE_REQUEST,
|
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
|
|
|
}
|