function TestDatabase::insertAssert
Same name in other branches
- 9 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.
2 calls to TestDatabase::insertAssert()
- simpletest_insert_assert in core/
modules/ simpletest/ simpletest.module - Store an assertion from outside the testing context.
- 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\TestCode
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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.