Codeception test DB with .env file
19 Dec 2018In file codeception.yml
add 1
params:
- .env
like
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
params:
- .env
In *.suite.yml
files 2
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost:8000
- Db:
dsn: "mysql:host=%ORDERS_DATABASE_HOST%;dbname=%ORDERS_DATABASE_NAME%"
user: "%ORDERS_DATABASE_USERNAME%"
password: "%ORDERS_DATABASE_PASSWORD%"
databases:
orderDB:
dsn: "mysql:host=%ORDERS_DATABASE_HOST%;dbname=%ORDERS_DATABASE_NAME%"
user: "%ORDERS_DATABASE_USERNAME%"
password: "%ORDERS_DATABASE_PASSWORD%"
newsDB:
dsn: "mysql:host=%NEWS_DATABASE_HOST%;dbname=%NEWS_DATABASE_NAME%"
user: "%NEWS_DATABASE_USERNAME%"
password: "%NEWS_DATABASE_PASSWORD%"
- \Helper\Acceptance
In test cest.
public function accessDB(\AcceptanceTester $I)
{
$I->amConnectedToDatabase('orderDB');
$I->seeInDatabase('table_name', ['column_name' => 'value']);
$I->amConnectedToDatabase('newsDB');
$I->seeInDatabase('table_name', ['column_name' => 'value']);
}