You are here

protected function CacheServicesTrait::populateRawCacheServices in Supercache 2.0.x

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

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

\Drupal\supercache\Cache\CacheRawFactoryInterface

Return value

string[] The name of the populated services.

File

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

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 populateRawCacheServices() {

  /** @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();
  $this->container
    ->set('rawbackend.wincache', new WincacheRawBackendFactory($app_root, $site_path));
  $this->container
    ->set('rawbackend.couchbase', new CouchbaseRawBackendFactory($manager, $app_root, $site_path));
  $this->container
    ->set('rawbackend.apcu', new ApcuRawBackendFactory($app_root, $site_path));
  $this->container
    ->set('rawbackend.database', new DatabaseRawBackendFactory($connection));

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

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

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

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

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