If database.restore_after_test is set, and a scenario is tagged "db", create a database backup.

The database will be restored from this backup via maybeRestoreDatabase().

@BeforeScenario @db

@param BeforeScenarioScope $scope
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);
    }
1329299
protected static function hasScope(ContextInterface $context, string $scope): bool
    {
        $result = false;

        if (static::ctxHasCurrentAccount($context) === true) {
            /** @var PassportAccountInterface $account */
            $account = self::ctxGetCurrentAccount($context);
            $result  = $account->hasScope($scope);
        }

        return $result;
    }
1090056
public function setScope($scope)
    {
        if (empty($scope)) {
            return $this->clearScope();
        }

        session()->put($this->getSessionKey(static::TYPE_SCOPE), $scope);

        return $this;
    }
674954
public function associateScope(SessionEntity $session, ScopeEntity $scope)
    {
        $this->getConnection()->table('oauth_session_scopes')->insert([
            'session_id' => $session->getId(),
            'scope_id' => $scope->getId(),
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now(),
        ]);
    }
1330816
public function addDefaultScope(IScope $scope)
    {
        if (!$this->defaultScopes->contains($scope)) {
            $this->defaultScopes->attach($scope);
        } else {
            throw new \InvalidArgumentException("Scope '{$scope->getId()}' is already registered as default scope.");
        }
    }
676439
public function newQueryWithoutScope($scope)
    {
        $this->getGlobalScope($scope)->remove($builder = $this->newQuery(), $this);

        return $builder;
    }
566674
public function scope(Scope $scope)
    {
        $callable = $scope->getQuery();

        if (is_string($callable)) {
            /*
             * Adds a Class "ClassName::class" syntax.
             *
             * @note In this case Query class should implement Contracts\Module\Queryable interface.
             * @example: (new Scope('name'))->setQuery(Queryable::class);
             */
            if (class_exists($callable)) {
                $object = app($callable);

                if (!method_exists($object, 'query')) {
                    throw new \Terranet\Administrator\Exception(
                        sprintf(
                            'Query object %s should implement %s interface',
                            get_class($object),
                            \Terranet\Administrator\Contracts\Module\Queryable::class
                        )
                    );
                }

                $this->query = $object->query($this->query);

                return $this;
            }

            /*
             * Allows "SomeClass@method" syntax.
             *
             * @example: (new Scope('name'))->addQuery("User@active")
             */
            if (str_contains($callable, '@')) {
                list($object, $method) = explode('@', $callable);

                $this->query = app($object)->$method($this->query);

                return $this;
            }
        }

        /*
         * Allows adding a \Closure as a query;
         *
         * @example: (new Scope('name'))->setQuery(function($query) { return $this->modify(); })
         */
        if ($callable instanceof Closure) {
            $this->query = $callable($this->query);

            return $this;
        }

        /*
         * Accepts callable builder
         *
         * @example: (new Scope('name'))->setQuery([SomeClass::class, "queryMethod"]);
         */
        if (is_callable($callable)) {
            list($object, $method) = $callable;

            if (is_string($object)) {
                $object = app($object);
            }

            // Call Model Scope immediately when detected.
            //
            // @note: We don't use call_user_func_array() here
            // because of missing columns in returned query.
            $this->query = with(
                $this->model->is($object) ? $this->query : $object
            )->{$method}($this->query);
        }

        return $this;
    }
190539
public void setScope(String scope) {
        if (scope.equalsIgnoreCase("page")) {
            this.scope = PageContext.PAGE_SCOPE;
        } else if (scope.equalsIgnoreCase("request")) {
            this.scope = PageContext.REQUEST_SCOPE;
        } else if (scope.equalsIgnoreCase("session")) {
            this.scope = PageContext.SESSION_SCOPE;
        } else if (scope.equalsIgnoreCase("application")) {
            this.scope = PageContext.APPLICATION_SCOPE;
        }
        // TODO: Add error handling?  Needs direction from spec.
    }
520909
function setScope (scope) {
    // throw error if attempting operation on complete audit record
    assert.ok(!this.complete, 'cannot setScope on complete audit record')
    // set scope value
    this.scope = scope
    // allow request is complete
    this.complete = true
    // debug
    debug(this)
    // return set value
    return this.scope
}
68453
public static function alterNodeParameters(BeforeNodeCreateScope $scope) {
    call_user_func('parent::alterNodeParameters', $scope);
    // @see `features/api.feature`
    // Change 'published on' to the expected 'created'.
    $node = $scope->getEntity();
    if (isset($node->{"published on"})) {
      $node->created = $node->{"published on"};
      unset($node->{"published on"});
    }
  }
1113815
private function createCreateForm(Scope $scope)
    {
        $form = $this->createForm(new ScopeType(), $scope, array(
            'action' => $this->generateUrl('admin_scope_create'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }
900735
public function scoped(Scope $scope)
	{
		if($scope instanceof Dependent)
		{
			$this->scope = NULL;
		}
		else
		{
			$this->scope = get_class($scope);
		}
		
		return $this;
	}
1294721
protected function after_restore() {
        global $DB;

        $contextid = $this->task->get_contextid();
        $instanceid = $this->task->get_activityid();
        $olditemid = $this->task->get_old_activityid();

        $DB->set_field('tag_instance', 'itemid', $instanceid, array('contextid' => $contextid, 'itemid' => $olditemid));
    }
293698
public function resetLocalScope()
    {
        // Restore previous un-completed lookup chain if set
        $previousLocalState = $this->localStack ? array_pop($this->localStack) : null;
        array_splice($this->itemStack, $this->localIndex + 1, count($this->itemStack), $previousLocalState);

        list(
            $this->item,
            $this->itemIterator,
            $this->itemIteratorTotal,
            $this->popIndex,
            $this->upIndex,
            $this->currentIndex
        ) = end($this->itemStack);
    }
956705
public function afterScenarioEmail(AfterScenarioScope $scope) {
    $mailsystem = $this->getCore()->getEditableConfig('mailsystem.settings');
    $mailsystem->set('defaults.sender', $this->mailsystem['sender'])->save();
  }
265938
public function update(ScopeInterface $scope): void
    {
        try {
            $now    = $this->ignoreException(function (): DateTimeImmutable {
                return new DateTimeImmutable();
            });
            $schema = $this->getDatabaseSchema();
            $this->updateResource($scope->getIdentifier(), [
                $schema->getScopesDescriptionColumn() => $scope->getDescription(),
                $schema->getScopesUpdatedAtColumn()   => $now,
            ]);
            $scope->setUpdatedAt($now);
        } catch (RepositoryException $exception) {
            $message = 'Scope update failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }
1150418
public function beforeScenario(BeforeScenarioTested $event)
    {
        if ('scenario' !== $this->lifetime) {
            return;
        }

        list($adapter, $fixtureClass) = $this->extractAdapterConfig($event->getFeature()->getTags());

        $this->executor->changeAdapter($adapter, $fixtureClass);
        $this->executor->purge();
    }