I'm trying to test a function that tries to fuzzy match a name to a name in the database.
Basically:
- givenName = 'Peter'
- familyName = 'Pan'
match('Peter Joe Pan') should return the record.
The query running on a MySQL db would be
Person::whereRaw('"' . $name . '" like concat(givenName , "%", familyName)')->first();
When I run my test where I test 'Peter Joe Pan', it works.
Recently I changed to using sqlite as a test database. Sqlite doesn't have the concat function, so I modified the function:
Person::whereRaw('"' . $name . '" like givenName || "%" || familyName)')->first();
The test now fails, i.e. the result is NULL.
If I change first() into firstOrFail(), I get an exception.
However, when I log Person::all() I get the "Peter Pan" record.
Also, when I build an sqlite database using Base and I run the query I get the record, i.e. the query is correct.
I'm at a loss what to do.
If I cannot solve this problem, the only thing I can think of is switching back to using MySQL as test database.
Any suggestions?