laracastsluvr's avatar

Possible to change DB Driver on specific test class?

Hello,

my question is same as the title. Is it possible to use a different database driver for one specific test class?

I'm currently using in_memory sqlite for testing, but I have a specific feature I need to test which makes use of MySQL user declared variables using the := assignment operator. The := assignment operator (or maybe user variables) isn't supported by SQLite from what I'm reading online.

I make use of phpunit.xml to setup the testing environment with:

...
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
...
0 likes
4 replies
laracastsluvr's avatar

Not related to my issue. The OP there asks to change the entire test suite to a different db driver.

I need 99% of my test to use my default configuration that I'm currently using (with phpunit.xml).

I just have 1 specific test class that should use a different db driver (MySQL), because of stuff I use that are incompatible with sqlite.

I have already set up that driver in config/database.php I just need a way to use it in a specific test class.

programators's avatar

Sorry, I see

What about exclude and include groups in phpunit configuration for performing tests? have you thought ?

laracastsluvr's avatar
laracastsluvr
OP
Best Answer
Level 4

It is considered good practice to run the test suite with the actual "stack" of software your production environment will have. I learned this the hard way (cliche) by having "false positives" with SQLite when testing, but crash-n-burn in Production.

Please or to participate in this conversation.