You are here

public static function TestBase::insertAssert in Drupal 8

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.

Return value

Message ID of the stored assertion.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. Use simpletest_insert_assert() instead.

See also

https://www.drupal.org/node/3030340

\Drupal\simpletest\TestBase::assert()

\Drupal\simpletest\TestBase::deleteAssert()

1 call to TestBase::insertAssert()
TestBase::run in core/modules/simpletest/src/TestBase.php
Run all tests in this class.
1 method overrides TestBase::insertAssert()
InnocuousTest::insertAssert in core/modules/simpletest/tests/src/Kernel/TestDeprecatedTestHooks.php
Override to prevent any assertions from being stored.

File

core/modules/simpletest/src/TestBase.php, line 395

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

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'],
  ];

  // We can't use storeAssertion() because this method is static.
  return self::getDatabaseConnection()
    ->insert('simpletest')
    ->fields($assertion)
    ->execute();
}