You are here

protected function BackendChainImplementationUnitTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php, line 46

Class

BackendChainImplementationUnitTest
Unit test of backend chain implementation specifics.

Namespace

Drupal\Tests\Core\Cache

Code

protected function setUp() : void {
  parent::setUp();

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

  // 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();
  $this->chain
    ->appendBackend($this->firstBackend)
    ->appendBackend($this->secondBackend)
    ->appendBackend($this->thirdBackend);
}