You are here

public function VariationCacheTest::testIncompatibleVariationsException in VariationCache 8

Tests exception for a cache item that has incompatible variations.

@covers ::get @covers ::set

File

tests/src/Unit/VariationCacheTest.php, line 393

Class

VariationCacheTest
@coversDefaultClass \Drupal\variationcache\Cache\VariationCache @group Cache

Namespace

Drupal\Tests\variationcache\Unit

Code

public function testIncompatibleVariationsException() {

  // This should never happen. When someone first stores something in the
  // cache using context A and then tries to store something using context B,
  // something is wrong. There should always be at least one shared context at
  // the top level or else the cache cannot do its job.
  $this
    ->setExpectedException(\LogicException::class, "The complete set of cache contexts for a variation cache item must contain all of the initial cache contexts.");
  $this->housingType = 'house';
  $house_cacheability = (new CacheableMetadata())
    ->setCacheContexts([
    'house.type',
  ]);
  $this->gardenType = 'garden';
  $garden_cacheability = (new CacheableMetadata())
    ->setCacheContexts([
    'garden.type',
  ]);
  $this
    ->setVariationCacheItem('You have a nice garden!', $garden_cacheability, $garden_cacheability);
  $this
    ->setVariationCacheItem('You have a nice house!', $house_cacheability, $garden_cacheability);
}