Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework;
11
 
12
use function assert;
13
use function count;
14
use RecursiveIterator;
15
 
16
/**
17
 * @template-implements RecursiveIterator<int, Test>
18
 *
19
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
20
 */
21
final class TestSuiteIterator implements RecursiveIterator
22
{
23
    /**
24
     * @var int
25
     */
26
    private $position = 0;
27
 
28
    /**
29
     * @var Test[]
30
     */
31
    private $tests;
32
 
33
    public function __construct(TestSuite $testSuite)
34
    {
35
        $this->tests = $testSuite->tests();
36
    }
37
 
38
    public function rewind(): void
39
    {
40
        $this->position = 0;
41
    }
42
 
43
    public function valid(): bool
44
    {
45
        return $this->position < count($this->tests);
46
    }
47
 
48
    public function key(): int
49
    {
50
        return $this->position;
51
    }
52
 
53
    public function current(): Test
54
    {
55
        return $this->tests[$this->position];
56
    }
57
 
58
    public function next(): void
59
    {
60
        $this->position++;
61
    }
62
 
63
    /**
64
     * @throws NoChildTestSuiteException
65
     */
66
    public function getChildren(): self
67
    {
68
        if (!$this->hasChildren()) {
69
            throw new NoChildTestSuiteException(
70
                'The current item is not a TestSuite instance and therefore does not have any children.'
71
            );
72
        }
73
 
74
        $current = $this->current();
75
 
76
        assert($current instanceof TestSuite);
77
 
78
        return new self($current);
79
    }
80
 
81
    public function hasChildren(): bool
82
    {
83
        return $this->valid() && $this->current() instanceof TestSuite;
84
    }
85
}