我正试图在codeception中创建一个功能测试,在这里我可以检查数据库表是否被使用
<?php
$I = new FunctionalTester($scenario);
$I->am('A guest');
$I->wantTo('Sign up for an account');
$I->amOnPage('auth/register');
$I->fillField('username', 'testuser');
$I->fillField('first_name', 'test_name');
$I->fillField('last_name', 'test_last');
$I->fillField('email', 'test@test.com');
$I->fillField('password', 'test');
$I->click('Sign up!');
$I->seeInDatabase('users', ['username' => 'testuser', 'first_name' => 'test_name', 'last_name' => 'test_last', 'email' => 'test@test.com', 'slug' => 'testuser']);
这是yaml文件:
class_name: FunctionalTester
modules:
enabled: [Filesystem, FunctionalHelper, Db, PhpBrowser]
config:
Db:
dsn: 'mysql:host=localhost;dbname='db''
user: 'root'
password: 'pass!'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
PhpBrowser:
url: 'http://localhost:8000'
我得到错误:
Couldn't see in database "users", {"username":"testuser","first_name":"test_name","last_name":"test_last","email":"test@test.com","slug":"testuser"}:
No matching records found
Failed asserting that '0' is greater than 0.
但是,当我在浏览器中填写表单时,代码会工作,并且用户已注册
您应该尝试使用Laravel4/Laravel5
(您没有提到Laravel版本)模块,然后使用seeRecord方法。我对grabFromDatabase
也有同样的问题——它不起作用,但当我使用Laravel模块中的grabRecord
时,它工作得很好。