如何在测试环境中读取Symfony中的缓存值(使用CacheInterface)?
[Symfony5.1]我有一个使用缓存函数(带缓存接口)的控制器。但是,在功能测试中,我仍然有一个错误,因为在测试环境中,以下代码总是返回null:如何在测试环境中读取Symfony中的缓存值(使用CacheInterface)?,symfony,symfony5,Symfony,Symfony5,[Symfony5.1]我有一个使用缓存函数(带缓存接口)的控制器。但是,在功能测试中,我仍然有一个错误,因为在测试环境中,以下代码总是返回null: public function getMyFunction(CacheInterface $cache, string $code) { $result = $cache->get('result_.'.$code, function (ItemInterface $item) use ($code) {
public function getMyFunction(CacheInterface $cache, string $code)
{
$result = $cache->get('result_.'.$code, function (ItemInterface $item) use ($code) {
$item->expiresAt(new \DateTime('+1 day'));
return $this->getResult($code);
});
return array(
'result' => $result,
);
}
变量“result”在dev和prod环境中从不返回null。但是变量“result”在测试环境中总是“null”
我的印象是,我们无法在测试环境中执行“$cache->get()”
怎么办?在开发环境中禁用缓存?如果是,如何进行
谢谢:)