我在yii2中的项目的代码接收中的数据库配置中有问题。每次我执行codecept运行时。发生错误[yii \ db \ Exception] SQLSTATE [HY000] [1049]未知数据库yii2advanced_test,它是common / config / main-local上的数据库配置是“ mydb”。我用谷歌搜索解决方案并应用了它,但是没有任何效果。
这是我的main-local.php
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=mydb',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
];
并且我尝试将这段代码添加到functional.suite.yml
suite_namespace: frontend\tests\functional
actor: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- Db
config:
Db:
dsn: 'mysql:host=localhost;dbname=mydb'
user: 'root'
password: ''
dump: tests/_data/dump.sql
仍然没有任何效果。请帮助我
在您的codeception.yml文件中,您应为codexeption定义yii2配置文件
# inside codeception.yml
modules:
config:
Yii2:
configFile: 'config/test.php'
并且在\ config中,您应该定义使用的数据库
<?php
// config/test.php
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
[
'id' => 'app-tests',
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=mydb',
]
]
]
);
return $config;