function PerformanceTestTrait::logQuery
Same name in other branches
- 10 core/tests/Drupal/Tests/PerformanceTestTrait.php \Drupal\Tests\PerformanceTestTrait::logQuery()
Logs a query in the performance data.
Parameters
\Drupal\Tests\PerformanceData $performance_data: The performance data object to log the query on.
string $query: The raw query.
array $args: The query arguments.
1 call to PerformanceTestTrait::logQuery()
- PerformanceTestTrait::collectPerformanceData in core/
tests/ Drupal/ Tests/ PerformanceTestTrait.php - Executes a callable and collects performance data.
File
-
core/
tests/ Drupal/ Tests/ PerformanceTestTrait.php, line 186
Class
- PerformanceTestTrait
- Provides various methods to aid in collecting performance data during tests.
Namespace
Drupal\TestsCode
protected static function logQuery(PerformanceData $performance_data, string $query, array $args) : void {
// Make queries with random variables invariable.
if (str_starts_with($query, 'INSERT INTO "semaphore"')) {
$args[':db_insert_placeholder_1'] = 'LOCK_ID';
$args[':db_insert_placeholder_2'] = 'EXPIRE';
}
elseif (str_starts_with($query, 'DELETE FROM "semaphore"')) {
$args[':db_condition_placeholder_1'] = 'LOCK_ID';
}
elseif (str_starts_with($query, 'SELECT "base_table"."uid" AS "uid", "base_table"."uid" AS "base_table_uid" FROM "users"')) {
$args[':db_condition_placeholder_0'] = 'ACCOUNT_NAME';
}
elseif (str_starts_with($query, 'SELECT COUNT(*) AS "expression" FROM (SELECT 1 AS "expression" FROM "flood" "f"')) {
$args[':db_condition_placeholder_1'] = 'CLIENT_IP';
$args[':db_condition_placeholder_2'] = 'TIMESTAMP';
}
elseif (str_starts_with($query, 'UPDATE "users_field_data" SET "login"')) {
$args[':db_update_placeholder_0'] = 'TIMESTAMP';
}
elseif (str_starts_with($query, 'INSERT INTO "sessions"')) {
$args[':db_insert_placeholder_0'] = 'SESSION_ID';
$args[':db_insert_placeholder_2'] = 'CLIENT_IP';
$args[':db_insert_placeholder_3'] = 'SESSION_DATA';
$args[':db_insert_placeholder_4'] = 'TIMESTAMP';
}
elseif (str_starts_with($query, 'SELECT "session" FROM "sessions"')) {
$args[':sid'] = 'SESSION_ID';
}
elseif (str_starts_with($query, 'SELECT 1 AS "expression" FROM "sessions"')) {
$args[':db_condition_placeholder_0'] = 'SESSION_ID';
}
elseif (str_starts_with($query, 'DELETE FROM "sessions"')) {
$args[':db_condition_placeholder_0'] = 'TIMESTAMP';
}
elseif (str_starts_with($query, 'INSERT INTO "watchdog"')) {
$args[':db_insert_placeholder_3'] = 'WATCHDOG_DATA';
$args[':db_insert_placeholder_6'] = 'LOCATION';
$args[':db_insert_placeholder_7'] = 'REFERER';
$args[':db_insert_placeholder_8'] = 'CLIENT_IP';
$args[':db_insert_placeholder_9'] = 'TIMESTAMP';
}
elseif (str_starts_with($query, 'SELECT "name", "route", "fit" FROM "router"')) {
if (preg_match('@/sites/simpletest/(\\d{8})/files/css/(.*)@', $args[':patterns__0'], $matches)) {
$search = [
$matches[1],
$matches[2],
];
$replace = [
'TEST_ID',
'CSS_FILE',
];
foreach ($args as $name => $arg) {
if (!is_string($arg)) {
continue;
}
$args[$name] = str_replace($search, $replace, $arg);
}
}
}
elseif (str_starts_with($query, 'SELECT "base_table"."id" AS "id", "base_table"."path" AS "path", "base_table"."alias" AS "alias", "base_table"."langcode" AS "langcode" FROM "path_alias" "base_table"')) {
if (str_contains($args[':db_condition_placeholder_1'], 'files/css')) {
$args[':db_condition_placeholder_1'] = 'CSS_FILE';
}
}
elseif (str_starts_with($query, 'SELECT "name", "value" FROM "key_value_expire" WHERE "expire" >')) {
$args[':now'] = 'NOW';
$args[':keys__0'] = 'KEY';
}
// Inline query arguments and log the query.
$query = str_replace(array_keys($args), array_values(static::quoteQueryArgs($args)), $query);
$performance_data->logQuery($query);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.