Laravel 5内存测试 [英] Laravel 5 testing in memory

查看:157
本文介绍了Laravel 5内存测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过behat为我的Laravel 5大项目编写测试.

I am writing tests via behat for my large Laravel 5 project.

我在MySQL中有一个MySQL数据库的测试副本,还有一个该数据库的种子服务器,该种子服务器共享其他环境的一些种子服务器.所有这些都按预期工作.

I have a testing copy of my MySQL database in MySQL and a seeder for that database that shares some of the seeders of other environments. All of that works as expected.

但是,我尝试切换到使用sqlite内存数据库,因为它将大大加快我的自动化测试的速度,并且因为在每个behat场景开始时我都在运行"artsian migration:refresh --- seeder = TestDatabaseSeeder".

However, I tried switching to using a sqlite in-memory database because it would speed up my automated tests dramatically and because I'm running "artsian migrate:refresh ---seeder=TestDatabaseSeeder at the start of every behat scenario.

我遇到的问题是,我的一些种子数据导致sqlite抛出了非常无法描述的语法错误,但是MySQL对种子数据完全没问题.

The problem I'm having is that some of my seed data causes sqlite to throw a very non-descript syntax error but MySQL is completely fine with the seed data.

理想情况下,我想,我希望它在内存中使用MySQL来提高性能,并保持数据库引擎的一致性.运行测试时,有没有Laravel是否有简单的方法可以在内存中使用MySQL?不涉及重复&的解决方案以使sqlite满意的方式编辑迁移文件吗?

Ideally, I think, I'd like to have it use MySQL in-memory for performance purposes and to keep the database engine consistent. Is there an easy way with or without Laravel to use MySQL in memory when running tests? A solution that does NOT involve duplicating & editing migration files in a way that makes sqlite happy?

推荐答案

事实证明,sqlite不喜欢'逃脱的方式.

It turned out that sqlite didn't like the way ' were being escaped.

"\'"需要替换为". sqlite不支持枚举,所以我改变了迁移方式,使用字符串代替了枚举.

"\'" needed to be replaced with "''". And sqlite doesn't support enums so I changed out my migrations and use strings instead of enums.

这篇关于Laravel 5内存测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆