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\Tester\Result;
15 use IteratorAggregate;
18 * Aggregates multiple test results into a collection and provides informational API on top of that.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class TestResults implements TestResult, Countable, IteratorAggregate
24 const NO_TESTS = -100;
32 * Initializes test results collection.
34 * @param TestResult[] $results
36 public function __construct(array $results = array())
38 $this->results = $results;
44 public function isPassed()
46 return self::PASSED == $this->getResultCode();
52 public function getResultCode()
54 $resultCode = static::NO_TESTS;
55 foreach ($this->results as $result) {
56 $resultCode = max($resultCode, $result->getResultCode());
65 public function count()
67 return count($this->results);
73 public function getIterator()
75 return new ArrayIterator($this->results);
79 * Returns test results array.
81 * @return TestResult[]
83 public function toArray()
85 return $this->results;