File: RuleSetIteratorTest.php

package info (click to toggle)
composer 2.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,528 kB
  • sloc: php: 83,030; makefile: 59; xml: 39
file content (81 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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;
use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Test\TestCase;

class RuleSetIteratorTest extends TestCase
{
    /** @var array<RuleSet::TYPE_*, Rule[]> */
    protected $rules;
    /** @var Pool */
    protected $pool;

    protected function setUp(): void
    {
        $this->pool = new Pool();

        $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);

        $result = [];
        foreach ($ruleSetIterator as $rule) {
            $result[] = $rule;
        }

        $expected = [
            $this->rules[RuleSet::TYPE_REQUEST][0],
            $this->rules[RuleSet::TYPE_REQUEST][1],
            $this->rules[RuleSet::TYPE_LEARNED][0],
        ];

        self::assertEquals($expected, $result);
    }

    public function testKeys(): void
    {
        $ruleSetIterator = new RuleSetIterator($this->rules);

        $result = [];
        foreach ($ruleSetIterator as $key => $rule) {
            $result[] = $key;
        }

        $expected = [
            RuleSet::TYPE_REQUEST,
            RuleSet::TYPE_REQUEST,
            RuleSet::TYPE_LEARNED,
        ];

        self::assertEquals($expected, $result);
    }
}