我试图在代码中创建一个功能测试,在那里我可以检查数据库表是否在这里被测试是测试:
<?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.
然而,当我在浏览器中填写表单时,代码可以正常运行并且用户已注册
答案 0 :(得分:1)
您应该尝试使用Laravel4/Laravel5
(您没有提及Laravel版本)模块,然后使用seeRecord方法。我对grabFromDatabase
有完全相同的问题 - 它不起作用,但是当我在Laravel模块中使用grabRecord
时,它可以正常工作。