You are here

protected function CacheServicesTrait::populateCacheServices in Supercache 8

Same name and namespace in other branches
  1. 2.0.x src/Tests/Generic/Cache/CacheServicesTrait.php \Drupal\supercache\Tests\Generic\Cache\CacheServicesTrait::populateCacheServices()

Populates the container with a wide sample of cache factory services to test components that depend on caches.

\Drupal\Core\Cache\CacheFactoryInterface

Return value

string[] The name of the populated services.

1 call to CacheServicesTrait::populateCacheServices()
ChainedStorageTests::setUp in src/Tests/KeyValue/ChainedStorageTests.php

File

src/Tests/Generic/Cache/CacheServicesTrait.php, line 110

Class

CacheServicesTrait
Use this to populate the container with a wide set of cache services that can be used to test components that depend on caches.

Namespace

Drupal\supercache\Tests\Generic\Cache

Code

protected function populateCacheServices() {

  /** @var \Psr\Log\LoggerInterface */
  $logger = $this
    ->getMock(\Psr\Log\LoggerInterface::class);
  $app_root = '/';
  $site_path = 'mypath';

  // The testing system chokes
  // when database used during shutdown.
  new Settings([
    'chained_disable_shutdown' => TRUE,
  ]);
  $settings = \Drupal\Core\Site\Settings::getInstance();
  $manager = new CouchbaseManager($settings, $logger);
  $connection = \Drupal\Core\Database\Database::getConnection();
  $checksum = new \Drupal\supercache\Cache\DummyTagChecksum();
  $this->container
    ->set('backend.wincache', new WincacheBackendFactory($app_root, $site_path, $checksum));
  $this->container
    ->set('backend.couchbase', new CouchbaseBackendFactory($manager, $app_root, $site_path, $checksum, TRUE));
  $this->container
    ->set('backend.apcu', new ApcuBackendFactory($app_root, $site_path, $checksum));
  $this->container
    ->set('backend.database', new DatabaseBackendFactory($connection, $checksum));

  // Wincache + Couchbase
  $f = new ChainedFastBackendFactory($settings, 'backend.couchbase', 'backend.wincache');
  $f
    ->setContainer($this->container);
  $this->container
    ->set('backend.chained.couchbase_wincache', $f);

  // Wincache + Database
  $f = new ChainedFastBackendFactory($settings, 'backend.database', 'backend.wincache');
  $f
    ->setContainer($this->container);
  $this->container
    ->set('backend.chained.database_wincache', $f);

  // Apcu + Couchbase
  $f = new ChainedFastBackendFactory($settings, 'backend.couchbase', 'backend.apcu');
  $f
    ->setContainer($this->container);
  $this->container
    ->set('backend.chained.couchbase_apcu', $f);

  // Apcu + Database
  $f = new ChainedFastBackendFactory($settings, 'backend.database', 'backend.apcu');
  $f
    ->setContainer($this->container);
  $this->container
    ->set('backend.chained.database_apcu', $f);

  // Couchbase + Database
  $f = new ChainedFastBackendFactory($settings, 'backend.database', 'backend.couchbase');
  $f
    ->setContainer($this->container);
  $this->container
    ->set('backend.chained.database_couchbase', $f);
  return [
    'backend.wincache',
    'backend.couchbase',
    'backend.apcu',
    'backend.database',
    'backend.chained.couchbase_wincache',
    'backend.chained.database_wincache',
    'backend.chained.couchbase_apcu',
    'backend.chained.database_apcu',
    'backend.chained.database_couchbase',
  ];
}