public function ResultCacheTest::testTags in GraphQL 8.3
Same name and namespace in other branches
- 8.4 tests/src/Kernel/Framework/ResultCacheTest.php \Drupal\Tests\graphql\Kernel\Framework\ResultCacheTest::testTags()
Test if results cache properly acts on cache tag clears.
File
- tests/
src/ Kernel/ Framework/ ResultCacheTest.php, line 183
Class
- ResultCacheTest
- Test query result caching.
Namespace
Drupal\Tests\graphql\Kernel\FrameworkCode
public function testTags() {
$this
->mockField('root', [
'id' => 'root',
'name' => 'root',
'type' => 'String',
'response_cache_tags' => [
'a',
'b',
],
], NULL, function ($field) {
$field
->expects(static::exactly(2))
->method('resolveValues')
->willReturnCallback(function () {
(yield 'test');
});
});
// First call that will be cached.
$this
->query('{ root }');
// Invalidate a tag that is part of the result metadata.
$this->container
->get('cache_tags.invalidator')
->invalidateTags([
'a',
]);
// Another call will invoke the processor a second time.
$this
->query('{ root }');
// Invalidate a tag that is NOT part of the result metadata.
$this->container
->get('cache_tags.invalidator')
->invalidateTags([
'c',
]);
// Result will be served from cache.
$this
->query('{ root }');
}