E
E
EVOSandru62019-11-20 00:34:29
Docker
EVOSandru6, 2019-11-20 00:34:29

How to roll migration in laravel 5.8 and run tests from test .env.testing environment?

Good afternoon,
There are files with a key section:
.env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54321
DB_DATABASE=app
DB_USERNAME=app
DB_PASSWORD=secret
.env.testing:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=
54322 =app_test
DB_USERNAME=app_test
DB_PASSWORD=secret_test
From under docker I run:

docker-compose exec php-cli php artisan migrate --env=testing

I catch:
Nothing to migrate.
I clear the cache first:
Makefile:
clear-cache:
  $(_EXEC) $(_CLI_CTR) php artisan cache:clear
  $(_EXEC) $(_CLI_CTR) php artisan view:clear
  $(_EXEC) $(_CLI_CTR) php artisan config:cache
  $(_EXEC) $(_CLI_CTR) php artisan route:cache
  $(_SUDO) cat /dev/null > $(APP_PATH)/storage/logs/laravel.log
  $(_SUDO) rm -f $(APP_PATH)/cache/packages.php
  $(_SUDO) rm -f $(APP_PATH)/cache/services.php

Why is the environment not picked up?
Also, in phpunit.xml , I entered these sections for testing, in order to firstly connect to the test database and, as a result of the above, to catch the error:
<env name="DB_PORT" value="54322"/>
<env name="DB_DATABASE" value="app_test"/>
<env name="DB_USERNAME" value="app_test"/>
<env name="DB_PASSWORD" value="secret_test"/>

But records at tests are added to the main table. There are no tables in the test database at all.
Help with advice good people)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-11-20
@EVOSandru6

Because this is the environment. What is the point of having environment variables if they are committed somewhere anyway?
And if they don’t commit, then what’s the point of two .env files? env is only read from .env and nowhere else (and shouldn't be).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question