You are here

public static function TestDatabase::insertAssert in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::insertAssert()

Store an assertion from outside the testing context.

This is useful for inserting assertions that can only be recorded after the test case has been destroyed, such as PHP fatal errors. The caller information is not automatically gathered since the caller is most likely inserting the assertion on behalf of other code. In all other respects the method behaves just like \Drupal\simpletest\TestBase::assert() in terms of storing the assertion.

@internal

Parameters

string $test_id: The test ID to which the assertion relates.

string $test_class: The test class to store an assertion for.

bool|string $status: A boolean or a string of 'pass' or 'fail'. TRUE means 'pass'.

string $message: The assertion message.

string $group: The assertion message group.

array $caller: The an array containing the keys 'file' and 'line' that represent the file and line number of that file that is responsible for the assertion.

Return value

int Message ID of the stored assertion.

1 call to TestDatabase::insertAssert()
TestDatabase::logRead in core/lib/Drupal/Core/Test/TestDatabase.php
Reads the error log and reports any errors as assertion failures.

File

core/lib/Drupal/Core/Test/TestDatabase.php, line 211

Class

TestDatabase
Provides helper methods for interacting with the fixture database.

Namespace

Drupal\Core\Test

Code

public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) {

  // Convert boolean status to string status.
  if (is_bool($status)) {
    $status = $status ? 'pass' : 'fail';
  }
  $caller += [
    'function' => 'Unknown',
    'line' => 0,
    'file' => 'Unknown',
  ];
  $assertion = [
    'test_id' => $test_id,
    'test_class' => $test_class,
    'status' => $status,
    'message' => $message,
    'message_group' => $group,
    'function' => $caller['function'],
    'line' => $caller['line'],
    'file' => $caller['file'],
  ];
  return static::getConnection()
    ->insert('simpletest')
    ->fields($assertion)
    ->execute();
}