Issues I ran into when Testing in Laravel 5 with SQLite
James Fairhurst
94

i am having trouble getting this to work. I am using L5.4.

My config/database.php looks like =>

'default' => env('DB_CONNECTION', 'mysql'),

'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/database.sqlite',
'prefix' => '',
],

my .env file in the root looks like =>

DB_CONNECTION=sqlite

My phpunit.xml =>

<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value="storage/database.sqlite"/>
</php>

And my TestCase.php =>

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;

/**
* Setup method call
*
*
@return void
*/
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
}

/**
* Tear down method call
*
*
@return void
*/
public function tearDown()
{
parent::tearDown();
Artisan::call('migrate:rollback');
}
}

I get this error =>

Tests\Unit\UserTest::testUserCanBeDeleted
 ReflectionException: Class env does not exist

Whenever i run phpunit, the setUp method runs the migrations but i get this error on the down method. How do i fix this please? Thanks in advance

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.