Laravel 5 Test Environment Not Installed in Codeception Unit Tests

I use Laravel 5 and Codeception, and I would like to use the in-memory SQLite database for my unit tests, however I cannot get my environment to set β€œtesting” in Codeception. I am using the Laravel5 module and have the following definition in the unit.suite.yml file:

class_name: UnitTester modules: enabled: [Asserts, UnitHelper, Laravel5] config: Laravel5: environment_file: .env.testing 

I have a .env file that defines all of my local settings, and then a .env.testing file that defines all the parameters related to testing. However, apparently, he does not really establish the right environment.

To check the environment, I simply did:

 $this->assertEquals('testing', \App::environment()); 

and I always get:

 Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'testing' +'local' 

Does anyone know what I'm doing wrong?

+7
php unit-testing laravel laravel-5 codeception
source share
3 answers

Did you specify the environment name in the .env.testing file?

 APV_ENV=testing 
+4
source share

I am completely new to laravel, but just found that the only way to get tests running on my local machine and (for example) Codeship is with a .env when I need it. (I know this is not a very clean way, but hey, it works)

I have a local .env file:

 #.env.testing APP_ENV=testing DB_CONNECTION=default_mysql DB_DATABASE=test_db ... etc 

and

 #.env.codeship APP_ENV=codeship DB_CONNECTION=codeship 

For local tests, I made an alias:

 alias pl='rm .env; ln -s .env.testing .env; phpunit; rm .env; ln -s .env.local .env' 

Where .env.local is stored a copy of my local .env file.

And for the Codeships test pipeline:

 ln -s .env.codeship .env php artisan migrate --seed phpunit 

Database Configuration:

 // CODESHIP 'codeship' => [ 'driver' => 'mysql', 'username' => getenv('MYSQL_USER'), 'password' => getenv('MYSQL_PASSWORD'), // etc ], // LOCAL DEV // PHPUNIT 'default_mysql' => [ 'driver' => 'mysql', 'username' => env('DB_USERNAME', 'localhost'), 'password' => env('DB_PASSWORD', 'forge'), // etc ], 

If anyone has any better ideas, I'm glad to hear.

+1
source share

This may be because you have an env file defined in your global code configuration. In the codeception.yml file in the project root directory check the value for the parameters, there should be something like the following

 params: - .env.testing 
+1
source share

All Articles