X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FEnvironment%2FReader%2FContextEnvironmentReader.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FContext%2FEnvironment%2FReader%2FContextEnvironmentReader.php;h=71759e9953c0991f8e9f57fadf3e01eaf3d38388;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Behat/Context/Environment/Reader/ContextEnvironmentReader.php b/vendor/behat/behat/src/Behat/Behat/Context/Environment/Reader/ContextEnvironmentReader.php new file mode 100644 index 000000000..71759e995 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Context/Environment/Reader/ContextEnvironmentReader.php @@ -0,0 +1,93 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Context\Environment\Reader; + +use Behat\Behat\Context\Environment\ContextEnvironment; +use Behat\Behat\Context\Reader\ContextReader; +use Behat\Testwork\Call\Callee; +use Behat\Testwork\Environment\Environment; +use Behat\Testwork\Environment\Exception\EnvironmentReadException; +use Behat\Testwork\Environment\Reader\EnvironmentReader; + +/** + * Reads context-based environment callees using registered context loaders. + * + * @author Konstantin Kudryashov + */ +final class ContextEnvironmentReader implements EnvironmentReader +{ + /** + * @var ContextReader[] + */ + private $contextReaders = array(); + + /** + * Registers context loader. + * + * @param ContextReader $contextReader + */ + public function registerContextReader(ContextReader $contextReader) + { + $this->contextReaders[] = $contextReader; + } + + /** + * {@inheritdoc} + */ + public function supportsEnvironment(Environment $environment) + { + return $environment instanceof ContextEnvironment; + } + + /** + * {@inheritdoc} + */ + public function readEnvironmentCallees(Environment $environment) + { + if (!$environment instanceof ContextEnvironment) { + throw new EnvironmentReadException(sprintf( + 'ContextEnvironmentReader does not support `%s` environment.', + get_class($environment) + ), $environment); + } + + $callees = array(); + foreach ($environment->getContextClasses() as $contextClass) { + $callees = array_merge( + $callees, + $this->readContextCallees($environment, $contextClass) + ); + } + + return $callees; + } + + /** + * Reads callees from a specific suite's context. + * + * @param ContextEnvironment $environment + * @param string $contextClass + * + * @return Callee[] + */ + private function readContextCallees(ContextEnvironment $environment, $contextClass) + { + $callees = array(); + foreach ($this->contextReaders as $loader) { + $callees = array_merge( + $callees, + $loader->readContextCallees($environment, $contextClass) + ); + } + + return $callees; + } +}