doctrine2 – Symfony / Doctrine UnitTests with SQLite memory DB

我还在研究用于测试我的symfony2控制器的 PHP单元测试.我的测试类是WebTestCase的派生,测试正在进行GET或POST请求,检查一切是否正常.
我想测试所有底层,但我不想用测试弄乱我的数据库.我不想使用模拟ups,而是使用内存中的SQLite数据库,我可以在其中设置测试场景以检查所有修改.
我发现了很多关于如何使用doctrine 1.x做到这一点的提示,但它们不再起作用了.
所以我想要这样的东西:
class BlahblahTest extends WebTestCase {
    public function testXXXYYY() {
        // 1. Setup a new database with SQLite:memory:
        // 2. create the database and all tables according the entities in my project
        $this->createTestScenario(); // 3.
        $crawler = $this->client->request('GET','/testpage');  // 4.
        // 5. Lots of checks against the database and / or the $crawler data
    }
}

有机会获得这项工作吗?

提前致谢
亨尼斯

我从来没有在内存中使用过sqlite数据库但是为了测试我确实使用了保存的sqlite数据库.

为此你应该添加

# app/config/config_test.yml
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_sqlite
                path:     %kernel.cache_dir%/test.db

到你的测试配置(对我来说是config_test.yml)

您应该能够根据文档将其更改为内存

http://docs.doctrine-project.org/projects/doctrine-
dbal/en/latest/reference/configuration.html#pdo-sqlite

memory (boolean): True if the SQLite database should be in-memory (non-persistent). Mutually exclusive with path. path takes precedence.

所以配置应该是

# app/config/config_test.yml
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_sqlite
                memory:   true

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能