问题
I'm setting up Codeception's Db module and would like to use the parameters from my Symfony 2's parameters.yml file.
Basically something like this:
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Symfony2:
app_path: 'app'
var_path: 'app'
environment: 'test'
Db:
dsn: "mysql:host='%test_database_host%';dbname='%test_database_name%'"
user: "%test_database_user%"
password: "%test_database_password%"
dump: tests/_data/test_data.sql
The placeholders (e.g. %test_database_user%) aren't replaced by the values in the parameters.yml file in Symfony 2's app/config directory.
parameters.yml:
parameters:
test_database_name: testdb
test_database_host: 127.0.0.1
test_database_user: root
test_database_password: thisismypassword
What's the best way to do this?
Thanks.
回答1:
In order to use params you should add params config to codeception.yml:
params:
- env # to get params from environment vars
- params.yml # to get params from yaml (Symfony style)
- params.env # to get params from .env (Laravel style)
you can use param values using '%' placeholders:
modules:
enabled:
- Db:
dsn: %DB_DSN%
user: %DB_USER%
password: %DB_PASS%
This possibility exists since this PR : https://github.com/Codeception/Codeception/pull/2855
In your example, you can add the params into your codeception.yml, like this :
params:
- app/config/parameters.yml
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Symfony2:
app_path: 'app'
var_path: 'app'
environment: 'test'
Db:
dsn: "mysql:host='%test_database_host%';dbname='%test_database_name%'"
user: "%test_database_user%"
password: "%test_database_password%"
dump: tests/_data/test_data.sql
Be aware that you can not access parameters like %kernel.project_dir%
来源:https://stackoverflow.com/questions/26998611/using-parameter-placeholders-in-codeception-yml