4 * This file is part of the Behat.
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\Behat\Context\Environment\Reader;
13 use Behat\Behat\Context\Environment\ContextEnvironment;
14 use Behat\Behat\Context\Reader\ContextReader;
15 use Behat\Testwork\Call\Callee;
16 use Behat\Testwork\Environment\Environment;
17 use Behat\Testwork\Environment\Exception\EnvironmentReadException;
18 use Behat\Testwork\Environment\Reader\EnvironmentReader;
21 * Reads context-based environment callees using registered context loaders.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class ContextEnvironmentReader implements EnvironmentReader
28 * @var ContextReader[]
30 private $contextReaders = array();
33 * Registers context loader.
35 * @param ContextReader $contextReader
37 public function registerContextReader(ContextReader $contextReader)
39 $this->contextReaders[] = $contextReader;
45 public function supportsEnvironment(Environment $environment)
47 return $environment instanceof ContextEnvironment;
53 public function readEnvironmentCallees(Environment $environment)
55 if (!$environment instanceof ContextEnvironment) {
56 throw new EnvironmentReadException(sprintf(
57 'ContextEnvironmentReader does not support `%s` environment.',
58 get_class($environment)
63 foreach ($environment->getContextClasses() as $contextClass) {
64 $callees = array_merge(
66 $this->readContextCallees($environment, $contextClass)
74 * Reads callees from a specific suite's context.
76 * @param ContextEnvironment $environment
77 * @param string $contextClass
81 private function readContextCallees(ContextEnvironment $environment, $contextClass)
84 foreach ($this->contextReaders as $loader) {
85 $callees = array_merge(
87 $loader->readContextCallees($environment, $contextClass)