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);
    }
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);
    }
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 ) ; }
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
If database . restore_after_test is set and a scenario is tagged db create a database backup .