public function VariationCacheTest::setUp in VariationCache 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ VariationCacheTest.php, line 123
Class
- VariationCacheTest
- @coversDefaultClass \Drupal\variationcache\Cache\VariationCache @group Cache
Namespace
Drupal\Tests\variationcache\UnitCode
public function setUp() {
parent::setUp();
$this->requestStack = $this
->prophesize(RequestStack::class);
$this->memoryBackend = new MemoryBackend();
$this->cacheContextsManager = $this
->prophesize(CacheContextsManager::class);
$housing_type =& $this->housingType;
$garden_type =& $this->gardenType;
$house_orientation =& $this->houseOrientation;
$solar_type =& $this->solarType;
$this->cacheContextsManager
->convertTokensToKeys(Argument::any())
->will(function ($args) use (&$housing_type, &$garden_type, &$house_orientation, &$solar_type) {
$keys = [];
foreach ($args[0] as $context_id) {
switch ($context_id) {
case 'house.type':
$keys[] = "ht.{$housing_type}";
break;
case 'garden.type':
$keys[] = "gt.{$garden_type}";
break;
case 'house.orientation':
$keys[] = "ho.{$house_orientation}";
break;
case 'solar.type':
$keys[] = "st.{$solar_type}";
break;
default:
$keys[] = $context_id;
}
}
return new ContextCacheKeys($keys);
});
$this->variationCache = new VariationCache($this->requestStack
->reveal(), $this->memoryBackend, $this->cacheContextsManager
->reveal());
$this->housingTypeCacheability = (new CacheableMetadata())
->setCacheTags([
'foo',
])
->setCacheContexts([
'house.type',
]);
$this->gardenTypeCacheability = (new CacheableMetadata())
->setCacheTags([
'bar',
])
->setCacheContexts([
'house.type',
'garden.type',
]);
$this->houseOrientationCacheability = (new CacheableMetadata())
->setCacheTags([
'baz',
])
->setCacheContexts([
'house.type',
'garden.type',
'house.orientation',
]);
}