我在我的codeception.yml
测试根文件夹配置中有这个:
include:
- codeception/backend
- codeception/common
- codeception/console
paths:
log: codeception/_output
settings:
colors: true
modules:
enabled:
- Db
config:
Db:
dsn: 'mysql:host=localhost;dbname=db1_test'
user: 'root'
password: 'qwerty'
cleanup: true
然后在mu codeception/codeception.yml
:
namespace: tests\codeception\backend
actor: Tester
paths:
tests: .
log: _output
data: _data
helpers: _support
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
config:
# the entry script URL (without host info) for functional and acceptance tests
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
test_entry_url: http://ds3/index-test.php
然后我的codeception/unit.suite.yml
:
class_name: UnitTester
modules:
enabled:
- Db
但是当我从测试根文件夹运行codecept build
时出现以下错误:
[Codeception\Exception\ModuleConfigException]
Db module is not configured!
Options: dsn, user, password are required
Please, update the configuration and set all the required fields
如果我从- Db
删除codeception/unit.suite.yml
,则该模块根本不运行。似乎全局配置的modules
部分被完全忽略。如果全局配置中的Db
中存在拼写错误,它甚至不会影响任何内容。但是我需要为每个套件和每个应用程序只有一个Db配置。我究竟做错了什么?文档说明应该可以在全球范围内声明模块。
答案 0 :(得分:2)
好的,澄清一下:这是我的codecetion.yml文件(上面的不同项目,但针对您的场景进行了测试):
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
modules:
config:
DataHelper:
db:
host: 02corm.za.ds.xxxxxxx.com
user: xxxxxxx
password: yyyyyyy
port: 3306
env:
stubDelay: 2
otdWebhook: http://xxxxxx.com:9080/api/webhook/
otdStubUrl: http://xxxxxx.com:9080/api/
和我的api.suite.yml:
class_name: ApiTester
modules:
enabled:
- PhpBrowser
- REST
- ApiHelper
- DataHelper
- CurlHelper
- OtdHelper
- Asserts
- WooCommerceHelper
- ResponseHelper
config:
PhpBrowser:
url: http://dev.xxxx.co.za
curl:
CURLOPT_TIMEOUT: 50000 # timeout in seconds
REST:
url: http://dev.xxxx.co.za
timeout: 90
env:
mini:
modules:
config:
PhpBrowser:
url: http://xxxxxx.com:9080/api/
curl:
CURLOPT_TIMEOUT: 50000 # timeout in seconds
REST:
url: http://xxxxxx.com:9080/api/
dcr-static:
modules:
config:
PhpBrowser:
url: http://x.x.x.x:10080/api
curl:
CURLOPT_TIMEOUT: 50000 # timeout in seconds
REST:
url: http://x.x.x.x:10080/api
DataHelper:
db:
host: x.x.x.x
user: xxxxx
password: yyyy
port: 3307
env:
stubDelay: 2
otdWebhook: http://x.x.x.x:10080/api/webhook/otd
otdStubUrl: http://x.x.x.x:10080/otd-stub/service
在上面的设置中,我有两个环境:mini和dcr-static。
' mini'没有提供DataHelper配置,所以它使用的是codecetion.yml文件中的配置。
在' dcr-static'我为这个环境提供了一个替代配置,它被用来代替codecetion.yml文件中给出的配置
答案 1 :(得分:1)
它应该是这样的:
class_name: UnitTester
modules:
enabled:
- Db
config:
Db:
dsn: 'mysql:host=localhost;dbname=db_name_here;port=3306'
user: 'user_here'
password: 'password_here'
dump: ''
populate: false
cleanup: false
reconnect: true