加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

doctrine2 – Symfony / Doctrine UnitTests with SQLite memory

发布时间:2020-12-12 19:03:31 所属栏目:百科 来源:网络整理
导读:我还在研究用于测试我的symfony2控制器的 PHP单元测试.我的测试类是WebTestCase的派生,测试正在进行GET或POST请求,检查一切是否正常. 我想测试所有底层,但我不想用测试弄乱我的数据库.我不想使用模拟ups,而是使用内存中的SQLite数据库,我可以在其中设置测试
我还在研究用于测试我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读