PeterF's avatar

Unit testing DB

Hi All. Just wondering if I have missed something..... I am running MySQL for production, and needed to do a quick fix, which meant I added a new Scope with a

->whereRaw("DATE_FORMAT(entry_time, '%r') < ?", [$end]);

which is fine.... but then I went back to write some unit tests to complete the loop (not quite TDD, more DDT)... and eventually worked out my new found pain was because sqlite does not care for such things as DATE_FORMAT.

SO just doing a quick poll of the room... do people all start with sqlite until it no longer works (like this) and then move everything to a docker mysql (or something else).... or do people just not use sqlite for anything other than tinkering?

Just curious whatever else does.....

Thanks.

0 likes
3 replies
Sinnbeck's avatar

I used to go with sqlite until it didn't work out. But now I use a real database from the start to make sure I don't get any false positives in my tests. I use docker for my complete dev set up

1 like
PeterF's avatar

I am basically a docker newbie. I have done Andrew Schmelyun's docker course on here a few times, I am about to do it again.... my understanding is that a mysql docker container should really only be used for one database for a pile of reasons that I haven't bothered to try and disprove..... So what does your setup @sinnbeck look like? Or anyone else for that matter.... do you have multiple containers running at once? I have a docker mysql running for my dev db, and am wondering about the logistics of docker containers for testing..... is it just time to stop pretending and install Jenkins on my local box? Or a selfhosted gitlab.....

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@PeterF no need for a seperate container for testing. I have just one mysql instance with 2 databases. And no need for jenkins either. I personally run github actions when I push code, but I also run my tests locally while working.

For my docker set up, I personally use something called lando. It's a wrapper around docker, that makes setting up a project a breeze. I can setup a laravel project with nginx and mysql in a couple of minutes. It even comes with a testing database by default!

I wrote a guide to get started: https://sinnbeck.dev/posts/using-lando-to-run-laravel-in-docker

1 like

Please or to participate in this conversation.