function PerformanceTestTrait::assertMetrics

Assert metrics from a performance data value object.

Parameters

array $expected: The expected metrics.

\Drupal\Tests\PerformanceData $performance_data: An instance of the performance data value object.

Return value

void

10 calls to PerformanceTestTrait::assertMetrics()
AssetAggregationAcrossPagesTest::testFrontAndRecipesPages in core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php
Checks the asset requests made when the front and recipe pages are visited.
AssetAggregationAcrossPagesTest::testFrontAndRecipesPagesAuthenticated in core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php
Checks the asset requests made when the front and recipe pages are visited.
OpenTelemetryAuthenticatedPerformanceTest::testFrontPageAuthenticatedWarmCache in core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php
Logs front page tracing data with an authenticated user and warm cache.
OpenTelemetryFrontPagePerformanceTest::testFrontPageHotCache in core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php
Logs front page tracing data with a hot cache.
OpenTelemetryNodePagePerformanceTest::testNodePageHotCache in core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryNodePagePerformanceTest.php
Logs node page tracing data with a hot cache.

... See full list

File

core/tests/Drupal/Tests/PerformanceTestTrait.php, line 657

Class

PerformanceTestTrait
Provides various methods to aid in collecting performance data during tests.

Namespace

Drupal\Tests

Code

protected function assertMetrics(array $expected, PerformanceData $performance_data) : void {
    // Allow those metrics to have a range of +/- 500 bytes, so small changes
    // are not significant enough to break tests.
    $assertRange = [
        'ScriptBytes',
        'StylesheetBytes',
    ];
    $values = [];
    foreach ($expected as $name => $metric) {
        if (in_array($name, $assertRange)) {
            $this->assertCountBetween($metric - 500, $metric + 500, $performance_data->{"get{$name}"}(), "Asserting {$name}");
            unset($expected[$name]);
        }
        else {
            $values[$name] = $performance_data->{"get{$name}"}();
        }
    }
    $this->assertSame($expected, $values);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.