1
0
Fork 0
composer/tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php

82 lines
2.2 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
/*
* 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\GenericRule;
use Composer\DependencyResolver\Rule;
use Composer\DependencyResolver\RuleSet;
use Composer\DependencyResolver\RuleSetIterator;
use Composer\DependencyResolver\Pool;
2021-09-05 14:02:10 +00:00
use Composer\Semver\Constraint\MatchAllConstraint;
2020-02-07 03:18:45 +00:00
use Composer\Test\TestCase;
class RuleSetIteratorTest extends TestCase
{
2021-10-16 08:16:06 +00:00
/** @var array<RuleSet::TYPE_*, Rule[]> */
protected $rules;
2021-10-16 08:16:06 +00:00
/** @var Pool */
protected $pool;
2021-12-08 16:03:05 +00:00
protected function setUp(): void
{
2019-11-27 16:55:02 +00:00
$this->pool = new Pool();
2022-08-17 12:20:07 +00:00
$this->rules = [
RuleSet::TYPE_REQUEST => [
new GenericRule([], Rule::RULE_ROOT_REQUIRE, ['packageName' => '', 'constraint' => new MatchAllConstraint]),
new GenericRule([], Rule::RULE_ROOT_REQUIRE, ['packageName' => '', 'constraint' => new MatchAllConstraint]),
],
RuleSet::TYPE_LEARNED => [
new GenericRule([], Rule::RULE_LEARNED, 1),
],
RuleSet::TYPE_PACKAGE => [],
];
}
public function testForeach(): void
{
$ruleSetIterator = new RuleSetIterator($this->rules);
2022-08-17 12:20:07 +00:00
$result = [];
2012-01-23 08:21:36 +00:00
foreach ($ruleSetIterator as $rule) {
$result[] = $rule;
}
2022-08-17 12:20:07 +00:00
$expected = [
$this->rules[RuleSet::TYPE_REQUEST][0],
$this->rules[RuleSet::TYPE_REQUEST][1],
$this->rules[RuleSet::TYPE_LEARNED][0],
2022-08-17 12:20:07 +00:00
];
self::assertEquals($expected, $result);
}
2012-01-22 21:06:09 +00:00
public function testKeys(): void
2012-01-22 21:06:09 +00:00
{
$ruleSetIterator = new RuleSetIterator($this->rules);
2022-08-17 12:20:07 +00:00
$result = [];
2012-01-23 08:21:36 +00:00
foreach ($ruleSetIterator as $key => $rule) {
2012-01-22 21:06:09 +00:00
$result[] = $key;
}
2022-08-17 12:20:07 +00:00
$expected = [
RuleSet::TYPE_REQUEST,
RuleSet::TYPE_REQUEST,
RuleSet::TYPE_LEARNED,
2022-08-17 12:20:07 +00:00
];
2012-01-22 21:06:09 +00:00
self::assertEquals($expected, $result);
2012-01-22 21:06:09 +00:00
}
}