/** * Searches and runs provided step delegating all the process to the parent class * * Method overwritten to look for: * - Moodle exceptions * - Moodle debugging() calls * - PHP debug messages (depends on the PHP debug level) * * @param StepNode $step step node * @return StepEvent */ protected function executeStep(StepNode $step) { // Redirect to the parent to run the step. $afterEvent = parent::executeStep($step); // Catch Moodle Behat skip exception. if ($afterEvent->getException() instanceof SkippedException) { return new StepEvent($afterEvent->getStep(), $afterEvent->getLogicalParent(), $afterEvent->getContext(), StepEvent::SKIPPED, $afterEvent->getDefinition(), $afterEvent->getException(), null); } // We set $this->dispatchafterstep to true when a step is in the lower level // but if a step is throwing an exception it doesn't arrive to the point where // we set dispatchafterstep to true and the event is not dispatched; here we // set it but we also check failredstep so the parent steps (in a chain) don't // continue dispatching the event. if ($afterEvent->getResult() !== StepEvent::PASSED && $this->failedstep === false) { $this->dispatchafterstep = true; } // Extra step, looking for a moodle exception, a debugging() message or a PHP debug message. $checkingStep = new StepNode('Then', self::EXCEPTIONS_STEP_TEXT, $step->getLine()); $afterExceptionCheckingEvent = parent::executeStep($checkingStep); // If it find something wrong we overwrite the original step result. if ($afterExceptionCheckingEvent->getResult() == StepEvent::FAILED) { // Creating a mix of both StepEvents to report about it as a failure in the original step. $afterEvent = new StepEvent($afterEvent->getStep(), $afterEvent->getLogicalParent(), $afterEvent->getContext(), $afterExceptionCheckingEvent->getResult(), $afterEvent->getDefinition(), $afterExceptionCheckingEvent->getException(), null); } return $afterEvent; }