Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Call / CallResults.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\Call;
12
13 use ArrayIterator;
14 use Countable;
15 use Iterator;
16 use IteratorAggregate;
17
18 /**
19  * Aggregates multiple call results into a collection and provides an informational API on top of that.
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 final class CallResults implements Countable, IteratorAggregate
24 {
25     /**
26      * @var CallResult[]
27      */
28     private $results;
29
30     /**
31      * Initializes call results collection.
32      *
33      * @param CallResult[] $results
34      */
35     public function __construct(array $results = array())
36     {
37         $this->results = $results;
38     }
39
40     /**
41      * Merges results from provided collection into the current one.
42      *
43      * @param CallResults $first
44      * @param CallResults $second
45      *
46      * @return CallResults
47      */
48     public static function merge(CallResults $first, CallResults $second)
49     {
50         return new static(array_merge($first->toArray(), $second->toArray()));
51     }
52
53     /**
54      * Checks if any call in collection throws an exception.
55      *
56      * @return Boolean
57      */
58     public function hasExceptions()
59     {
60         foreach ($this->results as $result) {
61             if ($result->hasException()) {
62                 return true;
63             }
64         }
65
66         return false;
67     }
68
69     /**
70      * Checks if any call in collection produces an output.
71      *
72      * @return Boolean
73      */
74     public function hasStdOuts()
75     {
76         foreach ($this->results as $result) {
77             if ($result->hasStdOut()) {
78                 return true;
79             }
80         }
81
82         return false;
83     }
84
85     /**
86      * Returns amount of results.
87      *
88      * @return integer
89      */
90     public function count()
91     {
92         return count($this->results);
93     }
94
95     /**
96      * Returns collection iterator.
97      *
98      * @return Iterator
99      */
100     public function getIterator()
101     {
102         return new ArrayIterator($this->results);
103     }
104
105     /**
106      * Returns call results array.
107      *
108      * @return CallResult[]
109      */
110     public function toArray()
111     {
112         return $this->results;
113     }
114 }