public function BackendChainImplementationUnitTest::setUp

File

drupal/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php, line 58
Definition of Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest.

Class

BackendChainImplementationUnitTest
Tests implementation-specific functionality of the BackendChain backend.

Namespace

Drupal\Tests\Core\Cache

Code

public function setUp() {
  parent::setUp();

  // Set up three memory backends to be used in the chain.
  $this->firstBackend = new MemoryBackend('foo');
  $this->secondBackend = new MemoryBackend('bar');
  $this->thirdBackend = new MemoryBackend('baz');

  // Set an initial fixed dataset for all testing. The next three data
  // collections will test two edge cases (last backend has the data, and
  // first backend has the data) and will test a normal use case (middle
  // backend has the data). We should have a complete unit test with those.
  // Note that in all cases, when the same key is set on more than one
  // backend, the values are voluntarily different, this ensures in which
  // backend we actually fetched the key when doing get calls.
  // Set a key present on all backends (for delete).
  $this->firstBackend
    ->set('t123', 1231);
  $this->secondBackend
    ->set('t123', 1232);
  $this->thirdBackend
    ->set('t123', 1233);

  // Set a key present on the second and the third (for get), those two will
  // be different, this will ensure from where we get the key.
  $this->secondBackend
    ->set('t23', 232);
  $this->thirdBackend
    ->set('t23', 233);

  // Set a key on only the third, we will ensure propagation using this one.
  $this->thirdBackend
    ->set('t3', 33);

  // Create the chain.
  $this->chain = new BackendChain('foobarbaz');
  $this->chain
    ->appendBackend($this->firstBackend)
    ->appendBackend($this->secondBackend)
    ->appendBackend($this->thirdBackend);
}