Pixelairport's avatar

phpunit.xml does not use my sqlite settings

I start to learn testing. After a lot of tests I realized, that even if i setup my phpunit.xml to use sqlite, it uses my main database, which is mysql.

I have this in my phpunit.xml:

    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="DB_CONNECTION" value="sqlite" />
    <server name="DB_DATABASE" value=":memory:" />

I don't want to use my production database for all my tests. I think it is better to use another one. But what have I forgot?

0 likes
10 replies
tykus's avatar

How are you running your tests; inside PHPStorm, or on the commandline?

Pixelairport's avatar

With terminal while inside homestead/vagrant.

  1. vagrant ssh
  2. phpunit --filter=myTestFile
tykus's avatar

Does phpunit refer to you project's dependency or a globally installed PHPUnit? If you alias phpunit, what do you see?

Sinnbeck's avatar

Do you by any chance set the connection on your models?

protected $connection = 'mysql';
Pixelairport's avatar

No. I dont set this be my own. I have the default user model and then another one:

class Trailer extends Model
{
    protected $fillable = [
        'title', 'tmdb_movie_id', 'site', 'key', 'size'
    ];
}
Sinnbeck's avatar

At the top it says the following?

use Illuminate\Database\Eloquent\Model;

Where did you place phpunit.xml? In the project root?

Pixelairport's avatar

Yes. This is done by laravel as default. I changed nothing. I just set the two lines in phpunit.xml which is in root folder. Laravel comes with phpunit out of the box.

Pixelairport's avatar
Pixelairport
OP
Best Answer
Level 12

Ok. After a lot of hours i found the problem. It was my fault... I ever was thinking that

php artisan config:cache

does the same as

php artisan config:clear & php artisan cache:clear

But that isn't so... not sure why... but when i do the second version (first config:clear then cache:clear) it works.

1 like
tykus's avatar

Why are you caching your config in a local/testing environment at all?

Please or to participate in this conversation.