数据库内存 - 移民。无法登录

时间:2014-05-04 17:26:07

标签: symfony testing functional-testing

我使用fosuserbundle进行身份验证。

测试期间的数据库设置为内存:

#config_test.yml
  doctrine:
    dbal:
        driver: pdo_sqlite
        path: :memory:
        memory: true
    orm:
        auto_generate_proxy_classes: true
        auto_mapping: true

测试文件看起来像那样(只有游乐场才能解决):

Pasted

当我运行测试时,我得到302重定向到登录,这不应该发生。 这可能有什么问题?

当我更改配置以使用开发mysql连接时 - 它运行良好 - 响应没有重定向且正文正确。

1 个答案:

答案 0 :(得分:0)

好的,我设法找出它为什么会发生。

我深入研究了Client类及其doRequest方法。

 protected function doRequest($request)
    {
        // avoid shutting down the Kernel if no request has been performed yet
        // WebTestCase::createClient() boots the Kernel but do not handle a request
        if ($this->hasPerformedRequest) {
            $this->kernel->shutdown();
        } else {
            $this->hasPerformedRequest = true;
        }

        if ($this->profiler) {
            $this->profiler = false;

            $this->kernel->boot();
            $this->kernel->getContainer()->get('profiler')->enable();
        }

        return parent::doRequest($request);
    }

因此内核正在关闭每个请求,数据库将从内存中删除。这是我99%的猜测。

除了使用其他客户端库

之外,我无法做任何事情