4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Call;
16 use IteratorAggregate;
19 * Aggregates multiple call results into a collection and provides an informational API on top of that.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 final class CallResults implements Countable, IteratorAggregate
31 * Initializes call results collection.
33 * @param CallResult[] $results
35 public function __construct(array $results = array())
37 $this->results = $results;
41 * Merges results from provided collection into the current one.
43 * @param CallResults $first
44 * @param CallResults $second
48 public static function merge(CallResults $first, CallResults $second)
50 return new static(array_merge($first->toArray(), $second->toArray()));
54 * Checks if any call in collection throws an exception.
58 public function hasExceptions()
60 foreach ($this->results as $result) {
61 if ($result->hasException()) {
70 * Checks if any call in collection produces an output.
74 public function hasStdOuts()
76 foreach ($this->results as $result) {
77 if ($result->hasStdOut()) {
86 * Returns amount of results.
90 public function count()
92 return count($this->results);
96 * Returns collection iterator.
100 public function getIterator()
102 return new ArrayIterator($this->results);
106 * Returns call results array.
108 * @return CallResult[]
110 public function toArray()
112 return $this->results;