public static function TestDatabase::insertAssert in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::insertAssert()
- 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.
@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.
File
- core/
lib/ Drupal/ Core/ Test/ TestDatabase.php, line 208
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();
}