function PerformanceTestRecorder::registerService

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Test/PerformanceTestRecorder.php \Drupal\Core\Test\PerformanceTestRecorder::registerService()
  2. 10 core/lib/Drupal/Core/Test/PerformanceTestRecorder.php \Drupal\Core\Test\PerformanceTestRecorder::registerService()

Registers core.performance.test.recorder service.

Parameters

string $services_file: Path to the services file to register the service in.

bool $persistent: Whether the recorder should be in persistent mode. The persistent mode records using the state service so that the recorder will work on the site under test when requests are made. However, if we want to measure something used by the state system then this will be recursive. Also in kernel tests using state is unnecessary.

3 calls to PerformanceTestRecorder::registerService()
InstallerPerformanceTest::prepareSettings in core/tests/Drupal/FunctionalTests/Installer/InstallerPerformanceTest.php
Prepares site settings and services before installation.
InstallerRouterTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerRouterTest.php
Prepares the current environment for running the test.
InstallerTest::setUpProfile in core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php
Installer step: Select installation profile.

File

core/lib/Drupal/Core/Test/PerformanceTestRecorder.php, line 100

Class

PerformanceTestRecorder
Records the number of times specific events occur.

Namespace

Drupal\Core\Test

Code

public static function registerService(string $services_file, bool $persistent) : void {
    $services = Yaml::parse(file_get_contents($services_file));
    if (isset($services['services']['core.performance.test.recorder'])) {
        // Once the service has been marked as persistent don't change that.
        $persistent = $persistent || $services['services']['core.performance.test.recorder']['arguments'][0];
    }
    $services['services']['core.performance.test.recorder'] = [
        'class' => PerformanceTestRecorder::class,
        'arguments' => [
            $persistent,
            $persistent ? '@state' : NULL,
        ],
        'tags' => [
            [
                'name' => 'event_subscriber',
            ],
        ],
    ];
    file_put_contents($services_file, Yaml::dump($services));
}

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