Change record status: 
Project: 
Introduced in branch: 
main
Introduced in version: 
11.5.0
Description: 

\Drupal\Tests\PerformanceTestTrait has two new methods:

assertMetricsByName(string $name, PerformanceData $performance_data, array $metrics = []);
assertQueriesByName(string $name, array $queries);

These will store the expected metrics (as formatted YAML) and queries (as plain list of queries, one per line) in separate named files in a TestClassAssertions folder next to the test class.

If the files do not exist yet or the PERF_TEST_UPDATE environment variable is set to a value that evaluates to true (such as 1), the files will be updated instead of asserted.

If metric files do not exist yet and no specific set of metrics is provided, they are populated with a default list of common metrics. If they exist and the environment variable to update them is set, only the currently set top-level keys are set.

When the expectations need to be updated, it is possible to either delete specific files or the whole folder or set the environment variable, for example in phpunit.xml:

<env name="PERF_TEST_UPDATE" value="1"/>

Impacts: 
Module developers