public function ResultCacheTest::testUncacheableResult in GraphQL 8.4
Same name and namespace in other branches
- 8.3 tests/src/Kernel/Framework/ResultCacheTest.php \Drupal\Tests\graphql\Kernel\Framework\ResultCacheTest::testUncacheableResult()
Verify that uncacheable results are not cached.
File
- tests/
src/ Kernel/ Framework/ ResultCacheTest.php, line 67
Class
- ResultCacheTest
- Test query result caching.
Namespace
Drupal\Tests\graphql\Kernel\FrameworkCode
public function testUncacheableResult() : void {
$cacheable = $this
->getMockBuilder(CacheableDependencyInterface::class)
->setMethods([
'getCacheTags',
'getCacheMaxAge',
'getCacheContexts',
])
->getMock();
$cacheable
->expects($this
->any())
->method('getCacheTags')
->willReturn([]);
$cacheable
->expects($this
->any())
->method('getCacheMaxAge')
->willReturn(0);
$cacheable
->expects($this
->any())
->method('getCacheContexts')
->willReturn([]);
$dummy = $this
->getMockBuilder(Server::class)
->disableOriginalConstructor()
->setMethods([
'id',
])
->getMock();
$dummy
->expects($this
->exactly(2))
->method('id')
->willReturn('test');
$this
->mockResolver('Query', 'root', $this->builder
->compose($this->builder
->fromValue($cacheable), $this->builder
->callback(function () use ($dummy) {
return $dummy
->id();
})));
// The first request that is not supposed to be cached.
$this
->query('{ root }');
// This should invoke the processor a second time.
$this
->query('{ root }');
}