Hi guys,
I use mysql db in production and dev, but for testing I use sqlite in memory, because is it much faster. IMHO this is common. I did not have any problem until now. Now I need to test complicated custom sql query with some mysql specific functions like (year, month, sec_to_time, time_to_sec, timediff,...)
What is the best approach to test sql query with mysql specific function which are not present in sqlite?
Use something in common rather than a driver specific functionality (e.g. there is a FIELD function is MySQL which you cannot use in SQLite, but you can mimic that function using CASE WHEN statements)
Don't test that piece of code (you can use a phpunit group annotation and then mark that group as skipped)
Implement 2 separate solutions each for a particular SQL grammar.
I'd personally go for option 1 if possible, and option 2 if not. 100% test coverage is not a must IMHO.
I faced that issue and I created a view with the different syntaxes for SQLite and MySQL. So the tests runs the sqlite version and the migrate command runs the mysql version.
if (App::environment() == 'local') {
//Mysql goes here
} else {
//Sqlite goes here
}
Thanks, maybe I found the best solution. Don't use sqlite for testing ;-) because there are more differences between mysql and sqlite and in some cases some tests may pass in sqlite but not in mysql. Read this: