Php codeception未看到dump.sql
我正在使用Yi2和Codeception。问题是Codeception似乎看不到数据库转储。为了简单起见,我只考虑LogCeP验收测试:Php codeception未看到dump.sql,php,mysql,yii,codeception,Php,Mysql,Yii,Codeception,我正在使用Yi2和Codeception。问题是Codeception似乎看不到数据库转储。为了简单起见,我只考虑LogCeP验收测试: use tests\_pages\LoginPage; $I = new WebGuy($scenario); $I->wantTo('ensure that login works'); $loginPage = LoginPage::openBy($I); $I->see('Login', 'h1'); $I->amGoingTo(
use tests\_pages\LoginPage;
$I = new WebGuy($scenario);
$I->wantTo('ensure that login works');
$loginPage = LoginPage::openBy($I);
$I->see('Login', 'h1');
$I->amGoingTo('try to login with empty credentials');
$loginPage->login('', '');
$I->expectTo('see validations errors');
$I->see('Username cannot be blank.');
$I->see('Password cannot be blank.');
...
所以,当我跑步的时候
./vendor/bin/codecept run tests/acceptance/LoginCept.php
一切正常运行:
Acceptance Tests (1) ----------------------------------------
Trying to ensure that login works (LoginCept.php) Ok
-------------------------------------------------------------
但只要我添加以下行
echo $I->grabFromDatabase('user', 'name', ['id' => 1]);
测试开始失败:
Acceptance Tests (1) ----------------------------------------
Trying to ensure that login works (LoginCept.php) Error
-------------------------------------------------------------
Time: 2.11 seconds, Memory: 9.75Mb
There was 1 error:
---------
1) Failed to ensure that login works in LoginCept.php
#1 F:\site\tests\acceptance\LoginCept.php:8 <-- 8 is the number of added line
#2 F:\site\tests\acceptance\LoginCept.php:8
FAILURES!
\Yii::$app->db的打印输出提供:
yii\db\Connection Object
(
[dsn] => mysql:host=localhost;dbname=site_test
[username] => daemon
[password] => HsqyJSAbZC3q3KJa
[attributes] =>
[pdo] =>
[enableSchemaCache] =>
[schemaCacheDuration] => 3600
...
)
使用上面的凭据,我可以手动登录到我的数据库(在phpmyadmin中)
数据库转储位于F:\site\tests\\u data\dump.sql
中。我从名为站点的工作数据库中创建了它,并在其中进行了一些修改:
CREATE DATABASE IF NOT EXISTS `site_test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
USE `site_test`;
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` smallint(5),
`name` varchar(50)
);
INSERT INTO `user` VALUES (1,'admin');
Codeceptionbuild命令每次运行时,都会给出:
$ ./vendor/bin/codecept build
Building Guy classes for suites: acceptance, functional, unit
WebGuy includes modules: WebHelper, PhpBrowser
WebGuy.php generated successfully. 48 methods added
TestGuy includes modules: Filesystem, TestHelper, Yii2
TestGuy.php generated successfully. 53 methods added
CodeGuy includes modules: CodeHelper
CodeGuy.php generated successfully. 1 methods added
确保为套装配置启用了Db模块 然后,在使用Db模块的方法之前,需要运行
codecept build
通常,您应该在每次启用或禁用测试套件配置中的模块时运行它。很抱歉没有提到这一点,但我每次都会这样做。现在我将在问题中提到这一点。请运行
/vendor/bin/codecept run tests/acceptance/LoginCept.php--debug
查看更详细的输出,并确保在测试套件配置中启用了Db模块(在您的情况下是acceptance.suit.yml),然后重新构建WebGuyThank!将Db配置块从codeception.yml复制到acceptance.suit.yml后,它开始工作了!我原以为codeception.yml中的设置会被其他设置增强,但结果表明,并不是所有设置都被考虑在内。不必从global codeception.yml复制所有Db配置,只需启用Db模块,以便将启用:[Selenium2,Db]
添加到模块
部分。
$ ./vendor/bin/codecept build
Building Guy classes for suites: acceptance, functional, unit
WebGuy includes modules: WebHelper, PhpBrowser
WebGuy.php generated successfully. 48 methods added
TestGuy includes modules: Filesystem, TestHelper, Yii2
TestGuy.php generated successfully. 53 methods added
CodeGuy includes modules: CodeHelper
CodeGuy.php generated successfully. 1 methods added