You are here

public function ServiceTest::testLazyLoadingOfDependencies in Purge 8.3

Tests lazy loading of the 'purge.purger' and 'purge.queue' services.

See also

\Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticsService::__construct

\Drupal\purge\Plugin\Purge\DiagnosticCheck\DiagnosticsService::initializeChecks

File

tests/src/Kernel/DiagnosticCheck/ServiceTest.php, line 102

Class

ServiceTest
Tests DiagnosticsService.

Namespace

Drupal\Tests\purge\Kernel\DiagnosticCheck

Code

public function testLazyLoadingOfDependencies() : void {
  $this
    ->assertFalse($this->container
    ->initialized('purge.purgers'));
  $this
    ->assertFalse($this->container
    ->initialized('purge.queue'));
  $this
    ->initializeService();
  $this
    ->assertFalse($this->container
    ->initialized('purge.purgers'));
  $this
    ->assertFalse($this->container
    ->initialized('purge.queue'));

  // All the helpers on the service - except the constructor - lazy load the
  // services, but only when any of the check plugins require them. In this
  // case the 'memoryqueuewarning' plugin will trigger the queue and the
  // 'capacity' and 'purgersavailable' plugins will load 'purge.purgers'.
  $this->service
    ->isSystemOnFire();
  $this
    ->assertTrue($this->container
    ->initialized('purge.purgers'));
  $this
    ->assertTrue($this->container
    ->initialized('purge.queue'));
}