function PerformanceTestTrait::assertMetrics
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/PerformanceTestTrait.php \Drupal\Tests\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.
19 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.
- AssetAggregationAcrossPagesTest::testNodeAddPagesAuthor in core/
profiles/ demo_umami/ tests/ src/ FunctionalJavascript/ AssetAggregationAcrossPagesTest.php - Checks the node/add page asset requests as an author.
- JsonApiPerformanceTest::testGetIndividual in core/
modules/ jsonapi/ tests/ src/ FunctionalJavascript/ JsonApiPerformanceTest.php - Tests performance of the navigation toolbar.
File
-
core/
tests/ Drupal/ Tests/ PerformanceTestTrait.php, line 672
Class
- PerformanceTestTrait
- Provides various methods to aid in collecting performance data during tests.
Namespace
Drupal\TestsCode
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.