function BackendChainImplementationUnitTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::setUp()
  2. 8.9.x core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::setUp()
  3. 11.x 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 52

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.
    $time = new Time();
    $this->firstBackend = new MemoryBackend($time);
    $this->secondBackend = new MemoryBackend($time);
    $this->thirdBackend = new MemoryBackend($time);
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.