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 No return value.

18 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 front and recipe page asset requests as an authenticated user.
AssetAggregationAcrossPagesTest::testFrontAndRecipesPagesEditor in core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php
Checks the front and recipe page asset requests as an editor.
JsonApiPerformanceTest::testGetIndividual in core/modules/jsonapi/tests/src/FunctionalJavascript/JsonApiPerformanceTest.php
Tests performance of the navigation toolbar.
OpenTelemetryAuthenticatedPerformanceTest::doTestFrontPageAuthenticatedWarmCache in core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php
Logs front page tracing data with an authenticated user and warm cache.

... See full list

File

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

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.