How to use sqlite when testing Lumen. Hi,
I am wondering how do to this with Lumen because there is no database.php?
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="database.sqlite" />
<env name="DB_DATABASE" value=":memory:" />
Thanks,
Mick
It should just be the name of the connection
<env name="DB_CONNECTION" value="testing" />
@tykus I tried that first and it isn't working (my MySQL database gets reset, so I assume that it is connecting to that) Works OK in Laravel but this is new Lumen project.
@crnkovic thankyou for your valuable input.
Sorry, I think I remember you should use testing as the DB_CONNECTION - it uses SQLite and :memory: under the hood
Still doing the same, I now have this:
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="testing" />
</php>
I'll need to take a look at my only Lumen app to see how I am doing this...
Thanks @tykus , I appreciate your help.
@MickBee idk this just seems like a problem whose solution can be found on first couple results of a google search
@MickBee I can confirm my only PHPunit configuration for testing purposes for my Lumen app is:
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
Once again @crnkovic thanks for your helpful contribution. If it is that easy, why not post one of these links here?
@tykus thanks for looking, this is exactly the same as mine and it still resets my mySQL database, I wonder if something is wrong somewhere else.
@tykus do you have a database.php file or a config directory?
Not in the Lumen app - it all is buried in the vendor directory, but looks at the environment.variables.
Try clearing your config cache in case you have a cached config that is working against you.
Is your project;s phpunit.xml file being used at all; can you check using the -v option:
$ ./vendor/bin/phpunit -v
You should expect to see a path to the project's phpunit.xml, e.g.
Configuration: /path/to/your/project/phpunit.xml
You also can force the configuration using the -c option
$ ./vendor/bin/phpunit -c ./phpunit.xml
@tykus you are a genius, yes phpUnit.xml is used when I run from the command line.
I think that this means that my configuration is wrong in PHPStorm (this is where I am executing the tests from).
Ah! Never thought to ask where you were using PHPUnit!
I'm sure there is some config in PHPStorm where you can either (i) tell it to use the project's phpunit and.or (ii) where to find the phpunit config.
If you're all set, mark the best reply.
Yes, that has sorted it. If anyone else gets this, you need to set the default configuration file on the PHP->Test Frameworks page.
Please sign in or create an account to participate in this conversation.