2
我在Codeception中使用Yii2。問題是Codeception似乎沒有看到數據庫轉儲。爲簡單起見,我只考慮LoginCept驗收測試:只要我添加以下行codeception看不到dump.sql
Acceptance Tests (1) ----------------------------------------
Trying to ensure that login works (LoginCept.php) Ok
-------------------------------------------------------------
但是:
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
一切運行沒有錯誤
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!
下面我把配置文件的詳細信息。
codeception.yml文件具有以下內容:
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
memory_limit: 1024M
log: true
colors: true
modules:
enabled: [Db]
config:
Db:
dsn: 'mysql:host=localhost;dbname=site_test'
user: 'daemon'
password: 'HsqyJSAbZC3q3KJa'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
打印出\的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\_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');
Codeception 構建命令每次我運行它,得到:
$ ./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
對不起,沒有提到,但我每次都這樣做。我現在在問題中提到這一點。 – Andrew
請運行''./vendor/bin/codecept運行tests/acceptance/LoginCept.php --debug''查看更詳細的輸出 –
並且請確保您在測試套件配置中啓用了Db模塊(在您的情況下它是acceptance.suit.yml),然後重建WebGuy –