jrdavidson's avatar

Not Seeding Test Database

I'm trying to figure out why when I run make command it doesn't seed my testing database because when my test gets to the method I"m testing it says there are no roles in the database.

<?php

namespace Tests;

use Illuminate\Foundation\Testing\DatabaseTransactions;

class IntegrationTestCase extends TestCase
{
    use DatabaseTransactions;
}

Makefile

build:
    php artisan migrate:refresh --env="testing"
    php artisan db:seed --class="RolesTableSeeder" --env="testing"
    phpunit
APP_ENV=testing
APP_KEY=base64:zH6ySDqMKvAtbBwTFiKDK07/3cQoPOSGhrcEFM2HcmE=
BCRYPT_ROUNDS=4
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_CONNECTION=sync
MAIL_DRIVER=array
DB_HOST=127.0.0.1
DB_PORT=33060
DB_CONNECTION=mysql
DB_DATABASE=ets_laravel_testing
DB_USERNAME=homestead
DB_PASSWORD=secret
0 likes
4 replies
rawilk's avatar

Try using the Illuminate\Foundation\Testing\RefreshDatabase trait instead, and also I recommend storing test settings in your phpunit.xml file instead of another .env file.

You can still use mysql if you want, but I've found it sometimes better to use an in memory sqlite database instead. But again, that's ultimately up to you.

In your phpunit.xml file, you would just need to add the following to the php element:

<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
jrdavidson's avatar

If in the Makefile I filter to a specific test it will pass however if I run phpunit by itself without the filter of a specific test then it'll fail all but a couple of tests.

Please or to participate in this conversation.