Aug 23, 2017
0
Level 14
More Elegant Approach to Testing when SQLIte Squirms?
SQLite doesn't have a MONTH function. I'm testing my app using SQLite in memory (for the speed gains), but the following approach is really stupid in that I have bypassed the code I want to test.
Please share your ideas on how better to handle this type of scenario. Thanks in advance.
if (app()->environment() == 'testing') {
// sqlite
return $query->whereRaw('cast( strftime(\'%m\', primary_books.pub_month ) as INTEGER) = ? ', [(int) date('m', strtotime($pub_date))])
->whereRaw('cast( strftime(\'%Y\', primary_books.pub_month ) as INTEGER) = ? ', [(int) date('Y', strtotime($pub_date))]);
}
// mysql
return $query->whereRaw('MONTH(primary_books.pub_month) = ? ', [(int) date('m', strtotime($pub_date))])
->whereRaw('YEAR(primary_books.pub_month) = ? ', [(int) date('Y', strtotime($pub_date))]);
Please or to participate in this conversation.