【问题标题】:Why does functional testing create new records on my Redis query cache?为什么功能测试会在我的 Redis 查询缓存中创建新记录?
【发布时间】:2016-08-12 16:29:40
【问题描述】:

我刚刚使用以下配置在我的 symfony 应用程序上启用了查询缓存:

Doctine 缓存配置

doctrine_cache:
    providers:
        cache:
            namespace: '%cache_namespace%'
            chain:
                providers:
                    - array_cache
                    - redis_cache
                    - file_cache
        redis_cache:
            namespace: '%cache_namespace%'
            predis:
                host: "%redis_host%"
                port: "%redis_port%"
                password: "%redis_password%"
                timeout: "%redis_timeout%"
        array_cache:
            namespace: '%cache_namespace%'
            array: ~
        file_cache:
            namespace: '%cache_namespace%'
            file_system:
                directory: "%kernel.cache_dir%/application"

Doctrine ORM 配置

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        an_entity_manager:
            connection: connection
            mappings:
                AppBundle: ~
            naming_strategy: doctrine.orm.naming_strategy.underscore
            metadata_cache_driver:
                type: service
                id: "doctrine_cache.providers.cache"
            query_cache_driver:
                type: service
                id: "doctrine_cache.providers.cache"
            result_cache_driver:
                type: service
                id: "doctrine_cache.providers.cache"

我还进行了填充本地 sqlite 数据库而不是真实数据库的功能测试。我看到的是以下内容:

每次我运行测试时,我都会看到 Redis 缓存会创建新的键,即使是相同的记录也是如此。我猜这一定是因为在执行每个测试之前都会重新创建数据库,并且就缓存而言,新创建的行的内容并不重要,但我不能确定。

有谁知道这是否是预期的行为?

【问题讨论】:

  • 您的问题看起来有点令人困惑,因为您没有在这里进行单元测试。在真正的单元测试中,你会模拟你的连接,因为你不是在测试那个,而是你最小的可测试单元。
  • 你说得对,我实际上是指功能测试。将编辑问题

标签: caching redis symfony


【解决方案1】:

您应该在测试环境中禁用 Redis(以及所有不必要的外部依赖项)。这可以通过仅使用内存缓存覆盖您在测试环境中的配置来完成。

要了解更多环境和配置,您可以查看 Symfony 文档:http://symfony.com/doc/current/book/configuration.html#environment-configuration

【讨论】:

  • 可能是个好主意,但它不能回答我的问题。只是提及以避免其他用户可能的类似答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-20
  • 2020-05-09
  • 2011-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
相关资源
最近更新 更多