function SimpletestTestRunResultsStorage::getCurrentTestRunState

Same name in other branches
  1. 10 core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php \Drupal\Core\Test\SimpletestTestRunResultsStorage::getCurrentTestRunState()

Overrides TestRunResultsStorageInterface::getCurrentTestRunState

File

core/lib/Drupal/Core/Test/SimpletestTestRunResultsStorage.php, line 124

Class

SimpletestTestRunResultsStorage
Implements a test run results storage compatible with legacy Simpletest.

Namespace

Drupal\Core\Test

Code

public function getCurrentTestRunState(TestRun $test_run) : array {
    // Define a subquery to identify the latest 'message_id' given the
    // $test_id.
    $max_message_id_subquery = $this->connection
        ->select('simpletest', 'sub')
        ->condition('test_id', $test_run->id());
    $max_message_id_subquery->addExpression('MAX([message_id])', 'max_message_id');
    // Run a select query to return 'last_prefix' from {simpletest_test_id} and
    // 'test_class' from {simpletest}.
    $select = $this->connection
        ->select($max_message_id_subquery, 'st_sub');
    $select->join('simpletest', 'st', '[st].[message_id] = [st_sub].[max_message_id]');
    $select->join('simpletest_test_id', 'st_tid', '[st].[test_id] = [st_tid].[test_id]');
    $select->addField('st_tid', 'last_prefix', 'db_prefix');
    $select->addField('st', 'test_class');
    return $select->execute()
        ->fetchAssoc();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.