MickBee's avatar

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

0 likes
18 replies
tykus's avatar

It should just be the name of the connection

<env name="DB_CONNECTION" value="testing" />
MickBee's avatar

@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.

tykus's avatar

Sorry, I think I remember you should use testing as the DB_CONNECTION - it uses SQLite and :memory: under the hood

MickBee's avatar

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>

tykus's avatar

I'll need to take a look at my only Lumen app to see how I am doing this...

crnkovic's avatar

@MickBee idk this just seems like a problem whose solution can be found on first couple results of a google search

tykus's avatar

@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>
MickBee's avatar

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's avatar

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.

tykus's avatar

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
MickBee's avatar

@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).

tykus's avatar
tykus
Best Answer
Level 104

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.

1 like
MickBee's avatar

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 or to participate in this conversation.