/** * Gets the required context. * * Getting a context you get access to all the steps * that uses direct API calls; steps returning step chains * can not be executed like this. * * @throws coding_exception * @param string $classname Context identifier (the class name). * @return behat_base */ public static function get($classname) { if (!($subcontext = self::$environment->getContext($classname))) { throw coding_exception('The required "' . $classname . '" class does not exist'); } return $subcontext; }
/** * {@inheritdoc} */ public function readEnvironmentCallees(Environment $environment) { if ($environment instanceof UninitializedContextEnvironment) { // Read all TqExtension contexts. foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__, \FilesystemIterator::SKIP_DOTS)) as $path => $object) { $namespace = ltrim(str_replace(__DIR__, '', $path), DIRECTORY_SEPARATOR); // Allow names which not starts from "Raw" and ends by "Context.php". if (strrpos($namespace, 'Context.php') !== false && strpos($namespace, 'Raw') !== 0) { $class = str_replace('/', '\\', __NAMESPACE__ . '/' . rtrim($namespace, '.php')); if (!$environment->hasContextClass($class)) { $environment->registerContextClass($class); } } } } if (empty($this->callees)) { // Read all step definitions from available contexts. foreach ($environment->getContextClasses() as $class) { foreach ($this->contextReaders as $loader) { $this->callees = array_merge($this->callees, $loader->readContextCallees($environment, $class)); } } } return $this->callees; }
function it_generates_filename_from_step_name(ScreenshotTaker $screenshotTaker, StepFilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, StepNode $step, StepResult $result, Teardown $tearDown) { $event = new AfterStepTested($env->getWrappedObject(), $feature->getWrappedObject(), $step->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject()); $result->getResultCode()->willReturn(TestResult::FAILED); $filenameGenerator->convertStepToFileName($step)->willReturn('test.jpg')->shouldBeCalled(); $screenshotTaker->takeScreenshot('test.jpg')->shouldBeCalled(); $this->checkAfterStep($event); }
/** * {@inheritdoc} */ public function supportsEnvironmentAndStep(Environment $environment, StepNode $step) { if (!$environment instanceof ContextEnvironment) { return false; } if (!$environment->hasContexts()) { return false; } return null !== $this->getSnippetAcceptingContextClass($environment); }
/** * Gets the required context. * * Getting a context you get access to all the steps * that uses direct API calls; steps returning step chains * can not be executed like this. * * @throws Behat\Behat\Context\Exception\ContextNotFoundException * @param string $classname Context identifier (the class name). * @return behat_base */ public static function get($classname) { $suitename = self::$environment->getSuite()->getName(); $overridencontextname = 'behat_theme_' . $suitename . '_' . $classname; // Check if overridden context class exists. if ($suitename !== 'default') { try { $subcontext = self::$environment->getContext($overridencontextname); return $subcontext; } catch (Behat\Behat\Context\Exception\ContextNotFoundException $e) { // If context not found then it's not overridden. } } // Get the actual context. return self::$environment->getContext($classname); }
/** * {@inheritdoc} * * @throws AmbiguousMatchException */ public function searchDefinition(Environment $environment, FeatureNode $feature, StepNode $step) { $suite = $environment->getSuite(); $language = $feature->getLanguage(); $stepText = $step->getText(); $multi = $step->getArguments(); $definitions = array(); $result = null; foreach ($this->repository->getEnvironmentDefinitions($environment) as $definition) { $definition = $this->translator->translateDefinition($suite, $definition, $language); if (!($newResult = $this->match($definition, $stepText, $multi))) { continue; } $result = $newResult; $definitions[] = $newResult->getMatchedDefinition(); } if (count($definitions) > 1) { throw new AmbiguousMatchException($result->getMatchedText(), $definitions); } return $result; }
/** * Gets the required context. * * Getting a context you get access to all the steps * that uses direct API calls; steps returning step chains * can not be executed like this. * * @throws Behat\Behat\Context\Exception\ContextNotFoundException * @param string $classname Context identifier (the class name). * @return behat_base */ public static function get($classname) { $suitename = self::$environment->getSuite()->getName(); // If default suite, then get the default theme name. if ($suitename == 'default') { $suitename = theme_config::DEFAULT_THEME; } $overridencontextname = 'behat_theme_' . $suitename . '_' . $classname; // If contexts has not been checked before and doesn't exist then just use core one. if (!isset(self::$nonexistingcontexts[$overridencontextname])) { try { $subcontext = self::$environment->getContext($overridencontextname); return $subcontext; } catch (Behat\Behat\Context\Exception\ContextNotFoundException $e) { // If context not found then it's not overridden. self::$nonexistingcontexts[$overridencontextname] = 1; } } // Get the actual context. return self::$environment->getContext($classname); }
public function isolateEnvironment(Environment $environment, $method = null) { $instance = $this->createInstance($environment->getSuite(), $method); $environment = new SpecEnvironment($environment->getSuite(), $instance); return $environment; }
/** * Returns hook suite. * * @return Suite */ public function getSuite() { return $this->environment->getSuite(); }
function it_does_not_save_screenshot_if_there_isnt_any(ScreenshotTaker $screenshotTaker, ScreenshotUploader $screenshotUploader, FilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, ScenarioInterface $scenario, TestResult $result, Teardown $tearDown) { $event = new AfterScenarioTested($env->getWrappedObject(), $feature->getWrappedObject(), $scenario->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject()); $result->getResultCode()->willReturn(TestResult::FAILED); $screenshotTaker->hasScreenshot()->willReturn(false)->shouldBeCalled(); $filenameGenerator->generateFileName($feature, $scenario)->shouldNotBeCalled(); $screenshotTaker->getImage()->shouldNotBeCalled(); $screenshotUploader->upload(Argument::any(), Argument::any())->shouldNotBeCalled(); $screenshotTaker->reset()->willReturn(null)->shouldBeCalled(); $this->saveScreenshot($event); }
/** * {@inheritdoc} */ public final function getBoundCallable() { return $this->environment->bindCallee($this->callee); }
/** * {@inheritdoc} */ public function supportsEnvironmentAndStep(Environment $environment, StepNode $step) { if (!$environment instanceof ContextEnvironment) { return false; } if (!$environment->hasContexts()) { return false; } return null !== $this->contextIdentifier->guessTargetContextClass($environment); }