public function CacheDecoratorTest::setUp

Sets up unit test environment.

Unlike Drupal\simpletest\WebTestBase::setUp(), UnitTestBase::setUp() does not install modules because tests are performed without accessing the database. Any required files must be explicitly included by the child class setUp() method.

Overrides UnitTestBase::setUp

File

drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php, line 41
Contains \Drupal\system\Tests\Plugin\CacheDecoratorTest.

Class

CacheDecoratorTest
Tests \Drupal\Core\Plugin\Discovery\CacheDecorator behavior.

Namespace

Drupal\system\Tests\Plugin

Code

public function setUp() {
  global $conf;
  parent::setUp();

  // Use a non-db cache backend, so that we can use DiscoveryTestBase (which
  // extends UnitTestBase).
  $conf['cache_classes'][$this->cacheBin] = 'Drupal\\Core\\Cache\\MemoryBackend';

  // Create discovery objects to test.
  $this->emptyDiscovery = new StaticDiscovery();
  $this->emptyDiscovery = new CacheDecorator($this->emptyDiscovery, $this->cacheKey . '_empty', $this->cacheBin);
  $this->discovery = new StaticDiscovery();
  $this->discovery = new CacheDecorator($this->discovery, $this->cacheKey, $this->cacheBin);

  // Populate sample definitions.
  $this->expectedDefinitions = array(
    'apple' => array(
      'label' => 'Apple',
      'color' => 'green',
    ),
    'cherry' => array(
      'label' => 'Cherry',
      'color' => 'red',
    ),
    'orange' => array(
      'label' => 'Orange',
      'color' => 'orange',
    ),
  );
  foreach ($this->expectedDefinitions as $plugin_id => $definition) {
    $this->discovery
      ->setDefinition($plugin_id, $definition);
  }
}