Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在测试环境中读取Symfony中的缓存值(使用CacheInterface)?_Symfony_Symfony5 - Fatal编程技术网

如何在测试环境中读取Symfony中的缓存值(使用CacheInterface)?

如何在测试环境中读取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) {

[Symfony5.1]我有一个使用缓存函数(带缓存接口)的控制器。但是,在功能测试中,我仍然有一个错误,因为在测试环境中,以下代码总是返回null:

    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()”

怎么办?在开发环境中禁用缓存?如果是,如何进行

谢谢:)