Issues (224)

tests/RequirementCollectionTest.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\RequirementChecker;
16
17
use PHPUnit\Framework\Attributes\CoversClass;
18
use PHPUnit\Framework\TestCase;
19
use function iterator_to_array;
20
21
/**
22
 * @internal
23
 */
24
#[CoversClass(RequirementCollection::class)]
25
class RequirementCollectionTest extends TestCase
26
{
27
    public function test_it_is_empty_by_default(): void
28
    {
29
        $requirements = new RequirementCollection();
30
31
        self::assertSame([], iterator_to_array($requirements, false));
32
        self::assertSame([], $requirements->getRequirements());
33
        self::assertCount(0, $requirements);
34
        self::assertTrue($requirements->evaluateRequirements());
0 ignored issues
show
The method evaluateRequirements() does not exist on Countable. It seems like you code against a sub-type of Countable such as HumbugBox451\KevinGH\Req...r\RequirementCollection or KevinGH\RequirementChecker\RequirementCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        self::assertTrue($requirements->/** @scrutinizer ignore-call */ evaluateRequirements());
Loading history...
35
    }
36
37
    public function test_it_can_have_and_evaluate_requirements(): void
38
    {
39
        $requirements = new RequirementCollection();
40
41
        $reqs = [
42
            $requirementA = new Requirement(
43
                new ConditionIsFulfilled(),
44
                'req tA',
45
                'req hA'
46
            ),
47
            $requirementB = new Requirement(
48
                new ConditionIsFulfilled(),
49
                'req tB',
50
                'req hB'
51
            ),
52
        ];
53
54
        foreach ($reqs as $requirement) {
55
            $requirements->add($requirement);
56
        }
57
58
        self::assertSame($reqs, iterator_to_array($requirements, false));
59
        self::assertSame($reqs, $requirements->getRequirements());
60
        self::assertCount(2, $requirements);
61
        self::assertTrue($requirements->evaluateRequirements());
62
63
        $requirements->addRequirement(
0 ignored issues
show
The method addRequirement() does not exist on Countable. It seems like you code against a sub-type of Countable such as HumbugBox451\KevinGH\Req...r\RequirementCollection or KevinGH\RequirementChecker\RequirementCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $requirements->/** @scrutinizer ignore-call */ 
64
                       addRequirement(
Loading history...
64
            $check = new ConditionIsNotFulfilled(),
65
            'req tC',
66
            'req hC'
67
        );
68
69
        self::assertCount(3, $requirements);
70
        self::assertFalse($requirements->evaluateRequirements());
71
72
        $retrievedRequirements = $requirements->getRequirements();
0 ignored issues
show
The method getRequirements() does not exist on Countable. It seems like you code against a sub-type of Countable such as HumbugBox451\KevinGH\Req...r\RequirementCollection or KevinGH\RequirementChecker\RequirementCollection or PharIo\Manifest\RequirementCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        /** @scrutinizer ignore-call */ 
73
        $retrievedRequirements = $requirements->getRequirements();
Loading history...
73
74
        self::assertSame($retrievedRequirements, iterator_to_array($requirements, false));
0 ignored issues
show
It seems like $requirements can also be of type Countable; however, parameter $iterator of iterator_to_array() does only seem to accept Traversable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        self::assertSame($retrievedRequirements, iterator_to_array(/** @scrutinizer ignore-type */ $requirements, false));
Loading history...
75
76
        self::assertSame($requirementA, $retrievedRequirements[0]);
77
        self::assertSame($requirementB, $retrievedRequirements[1]);
78
79
        $requirementC = $retrievedRequirements[2];
80
81
        self::assertSame($check, $requirementC->getIsFullfilledChecker());
82
        self::assertFalse($requirementC->isFulfilled());
83
        self::assertSame('req tC', $requirementC->getTestMessage());
84
        self::assertSame('req hC', $requirementC->getHelpText());
85
    }
86
}
87