Runs all the befores of containing contexts and then this context's befores in the
order they were added.

@param $scope The object scope of an Example being run for which local variables
need to be torn down.
325379
public function run_afters($scope) {    
    foreach ($this->_afters as $after) {
      $after($scope);
    }

    if ($this->_parent) {
      $this->_parent->run_afters($scope);
    }
  }
391400
public function purge($scope = null)
    {
        // Get scope if not passed
        if (null === $scope) {
            $scope = $this->getScope();
        }

        // Return result of purge
        return $this->getContainer()->purge($scope);
    }
998726
protected function callScope( callable $scope, $parameters = [] )
	{
		array_unshift( $parameters, $this );

		$query = $this->getQuery();

		// We will keep track of how many wheres are on the query before running the
		// scope so that we can properly group the added scope constraints in the
		// query as their own isolated nested where statement and avoid issues.
		$originalWhereCount = count( $query->wheres );

		$result = call_user_func_array( $scope, $parameters ) ?: $this;

		if ( $this->shouldNestWheresForScope( $query, $originalWhereCount ) )
		{
			$this->nestWheresForScope( $query, $originalWhereCount );
		}

		return $result;
	}
869751
private function runGateBefore(array $before_permissions)
    {
        $this->gate->before(function ($user, $ability) use ($before_permissions) {
            $result = true;
            foreach ($before_permissions as $restriction) {
                if (is_array($restriction)) {
                    $policy = reset($restriction);
                    $operator = key($restriction);
                } else {
                    $policy = $restriction;
                    $operator = 'and';
                }

                if (is_callable($policy)) {
                    $policy_method_return = call_user_func($policy, $user, $ability);
                } else {
                    list($class, $method) = explode('@', $policy);
                    $policy_method_return = app($class)->$method($user, $ability); // should return boolean
                }

                if ($operator === 'or' || $operator === '||') {
                    $result = $result || $policy_method_return;
                } else {
                    $result = $result && $policy_method_return;
                }
            }
            if ($result == true) {
                return true;
            }
        });
    }
1006517
public function beforeScenario(BeforeScenarioScope $scope)
    {
        $core = $scope->getEnvironment()->getContext(CoreContext::class);
        /* @var FileTransport $transport */
        $transport = $core->getServiceManager()->get('Core/MailService')->getTransport();
        $path = $transport->getOptions()->getPath() . '/*.eml';
        foreach (glob($path) as $filename) {
            unlink($filename);
        }

        $this->subjects = $this->fromMails = $this->toMails = array();
    }
695418
protected function callScope($scope, $parameters)
    {
        array_unshift($parameters, $this);

        return call_user_func_array(array($this->model, $scope), $parameters) ?: $this;
    }
744558
public function next($scope, $name = null)
    {
        Argument::i()
            ->test(1, 'object')          //argument 1 must be an object
            ->test(2, 'string', 'null'); //argument 2 must be a string or null

        $this->scope = $scope;
        $this->name = $name;

        return $this;
    }
1040792
public function clear($scope = null)
    {
        if ($scope === null) {
            $this->messages = array();
        } else {
            foreach ($this->messages as $key => $message) {
                if ($message['scope'] === $scope) {
                    unset($this->messages[$key]);
                }
            }
        }
        return $this;
    }
79807
public function removeScope($scope)
    {
        $this->validateScopeValue($scope);

        $key = $this->getScopeKey($scope);
        if (false === $key) {
            return $this;
        }

        unset($this->descriptor['scopes'][$key]);
        return $this;
    }
95064
protected function callScope(callable $scope, $parameters = [])
    {
        array_unshift($parameters, $this);

        $query = $this->getQuery();

        // We will keep track of how many wheres are on the query before running the
        // scope so that we can properly group the added scope constraints in the
        // query as their own isolated nested where statement and avoid issues.
        $originalWhereCount = count($query->wheres);

        $result = $scope(...array_values($parameters)) ?: $this;

        if (count($query->wheres) > $originalWhereCount) {
            $this->addNewWheresWithinGroup($query, $originalWhereCount);
        }

        return $result;
    }
1072997
protected function _beforeUpdate(DatabaseContextInterface $context)
    {
        if(isset($this->order) && $this->hasProperty('ordering')) {
            $this->order($this->order);
        }
    }
432395
public function maybeBackupDatabase(BeforeScenarioScope $scope)
    {
        $db = $this->getWordpressParameter('database');
        if (! $db['restore_after_test']) {
            return;
        }

        /*
         * We need the logic of this method to operate only once, and have access to the Context.
         * Otherwise, we would use the (static) BeforeSuiteScope hook.
         */
        $backup_file = $this->getWordpress()->getSetting('database_backup_file');
        if ($backup_file) {
            return;
        }

        // Get the file to use as a backup.
        $file = ! empty($db['backup_path']) ? $db['backup_path'] : '';

        // If the path specified is not a file, use it as the preferred folder to store a new backup.
        if (! $file || ! is_file($file) || ! is_readable($file)) {
            $file = $this->exportDatabase(['path' => $file]);
        }

        // Note: $file may be either an absolute OR relative file path.
        $this->getWordpress()->setSetting('database_backup_file', $file);
    }
874333
public function take_screenshot_after_failed( afterStepScope $scope )
	{
		if (99 === $scope->getTestResult()->getResultCode()) {
			$screenshot = $this->getSession()->getDriver()->getScreenshot();
			file_put_contents( '/tmp/behat-'.time().".png", $screenshot );
		}
	}
387634
public function beforeScenarioSetVariables(BeforeScenarioScope $scope)
    {
        $steps = [];
        if ($scope->getFeature()->hasBackground()) {
            $steps = $scope->getFeature()->getBackground()->getSteps();
        }
        $steps = array_merge($steps, $scope->getScenario()->getSteps());
        foreach ($steps as $step) {
            preg_match_all(static::VARIABLE_REGEX, $step->getText(), $matches);
            $variables_found = $matches[0];
            // Find variables in are TableNodes or PyStringNodes.
            $step_argument = $step->getArguments();
            if (!empty($step_argument) && $step_argument[0] instanceof TableNode) {
                preg_match_all(static::VARIABLE_REGEX, $step_argument[0]->getTableAsString(), $matches);
                $variables_found = array_filter(array_merge($variables_found, $matches[0]));
            }
            foreach ($variables_found as $variable_name) {
                if (!isset($this->values[$variable_name])) {
                    $value = $this->getDriver()->getRandom()->name(10);
                    // Value forced to lowercase to ensure it is machine-readable.
                    $this->values[$variable_name] = strtolower($value);
                }
            }
        }
    }
42724
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();
        $context = Tracer::spanContext();
        if ($context->enabled()) {
            $request->setHeader($this->propagator->key(), $this->propagator->formatter()->serialize($context));
        }
        $span = Tracer::startSpan([
            'name' => 'GuzzleHttp::request',
            'attributes' => [
                'method' => $request->getMethod(),
                'uri' => $request->getUrl()
            ],
            'kind' => Span::KIND_CLIENT
        ]);
        $this->scope = Tracer::withSpan($span);
    }
713801
public function gatherContexts(BeforeScenarioScope $scope)
    {
        /** @var InitializedContextEnvironment $environment */
        $environment = $scope->getEnvironment();
        $this->mainContext = $environment->getContext('FeatureContext');
    }
513310
public Variables beforeCall(PageContext pc) {
	Variables parent = pc.variablesScope();
	pc.setVariablesScope(scope);
	return parent;
    }