class EnvironmentCleaner implements EnvironmentCleanerInterface (View source)

Helper class for cleaning test environments.

Properties

protected string $root

Path to Drupal root directory.

protected Connection $testDatabase

Connection to the database being used for tests.

protected Connection $resultsDatabase

Connection to the database where test results are stored.

protected FileSystemInterface $fileSystem

The file system service.

protected OutputInterface $output

Console output.

Methods

__construct(string $root, Connection $test_database, Connection $results_database, OutputInterface $output, FileSystemInterface $file_system)

Construct an environment cleaner.

cleanEnvironment(bool $clear_results = TRUE, bool $clear_temp_directories = TRUE, bool $clear_database = TRUE)

Removes all test-related database tables and directories.

cleanDatabase()

Remove database entries left over in the fixture database.

int
doCleanDatabase()

Performs the fixture database cleanup.

cleanTemporaryDirectories()

Finds all leftover fixture site directories and removes them.

int
doCleanTemporaryDirectories()

Performs the cleanup of temporary test directories.

int
cleanResultsTable($test_id = NULL)

Clears test result tables from the results database.

Details

__construct(string $root, Connection $test_database, Connection $results_database, OutputInterface $output, FileSystemInterface $file_system)

Construct an environment cleaner.

Parameters

string $root

The path to the root of the Drupal installation.

Connection $test_database

Connection to the database against which tests were run.

Connection $results_database

Connection to the database where test results were stored. This could be the same as $test_database, or it could be different.

OutputInterface $output

A symfony console output object.

FileSystemInterface $file_system

The file_system service.

cleanEnvironment(bool $clear_results = TRUE, bool $clear_temp_directories = TRUE, bool $clear_database = TRUE)

Removes all test-related database tables and directories.

This method removes fixture files and database entries from the system under test.

Parameters

bool $clear_results

(optional) Whether to clear the test results database. Defaults to TRUE.

bool $clear_temp_directories

(optional) Whether to clear the test site directories. Defaults to TRUE.

bool $clear_database

(optional) Whether to clean up the fixture database. Defaults to TRUE.

cleanDatabase()

Remove database entries left over in the fixture database.

protected int doCleanDatabase()

Performs the fixture database cleanup.

Return Value

int

The number of tables that were removed.

cleanTemporaryDirectories()

Finds all leftover fixture site directories and removes them.

protected int doCleanTemporaryDirectories()

Performs the cleanup of temporary test directories.

Return Value

int

The count of temporary directories removed.

int cleanResultsTable($test_id = NULL)

Clears test result tables from the results database.

Parameters

$test_id

Test ID to remove results for, or NULL to remove all results.

Return Value

int

The number of results that were removed.