I have a query below that retrieves groups from the database; it works fine except when I run it through pest php test case and hit the controller; the test fails and says IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such function: YEAR
Here is my sql query
Group::query()
->selectRaw("YEAR(groups.created_at) as year,
MONTH(groups.created_at) as month,
DATE_FORMAT(groups.created_at, '%b') as short_month_format,
count('*') as count"
)
->whereIn('id', $ids)
->get();
Here is my pest php test case
test('authenticated user with permission will see analytics page ',function(){
$permission = 'permission';
actingWithPermission($this->user, $permission)
->get($this->route)
->assertStatus(302)
->assertDontSee("Text not to see goes here", false)
;
});
How can I fix mysql error above?
2
Answers
I was able to resolve the above issue by changing
DB CONNECTION
inphpunit.xml
fromsqlite
tomysql
.In my phpunit.xml
count(‘id’) is wrong , use count(‘id’) or other field .