Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Tester / Result / TestResults.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Tester\Result;
12
13 use ArrayIterator;
14 use Countable;
15 use IteratorAggregate;
16
17 /**
18  * Aggregates multiple test results into a collection and provides informational API on top of that.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class TestResults implements TestResult, Countable, IteratorAggregate
23 {
24     const NO_TESTS = -100;
25
26     /**
27      * @var TestResult[]
28      */
29     private $results;
30
31     /**
32      * Initializes test results collection.
33      *
34      * @param TestResult[] $results
35      */
36     public function __construct(array $results = array())
37     {
38         $this->results = $results;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function isPassed()
45     {
46         return self::PASSED == $this->getResultCode();
47     }
48
49     /**
50      * {@inheritdoc}
51      */
52     public function getResultCode()
53     {
54         $resultCode = static::NO_TESTS;
55         foreach ($this->results as $result) {
56             $resultCode = max($resultCode, $result->getResultCode());
57         }
58
59         return $resultCode;
60     }
61
62     /**
63      * {@inheritdoc}
64      */
65     public function count()
66     {
67         return count($this->results);
68     }
69
70     /**
71      * {@inheritdoc}
72      */
73     public function getIterator()
74     {
75         return new ArrayIterator($this->results);
76     }
77
78     /**
79      * Returns test results array.
80      *
81      * @return TestResult[]
82      */
83     public function toArray()
84     {
85         return $this->results;
86     }
87 }