我无法通过larabook教程获取代码测试。我正在通过第8集:Users但我的代码测试传递出现问题。即使从视频中纠正我的代码并添加记忆,我也会得到同样的错误。
There was 1 failure:
---------
1) Failed to perform actions and see result in SignUpCept (/home/vagrant/larabook/tests/functional/SignUpCept.php)
Couldn't see record "users",{"username":"JohnDoe","email":"john@example.com"}:
Couldn't find users with {"username":"JohnDoe","email":"john@example.com"}
Scenario Steps:
12. I see record "users",{"username":"JohnDoe","email":"john@example.com"}
11. I see "Welcome to Larabook"
10. I see current url equals ""
9 . I click "Sign Up","input[type="submit"]"
8 . I fill field "Password Confirmation:","demo"
7 . I fill field "Password:","demo"
6 . I fill field "Email:","john@example.com"
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
以下是我创建此记录的文件。有人可以帮我调试这个错误吗?
SignUpCept.php
$I = new FunctionalTester($scenario);
$I->am('a guest');
$I->wantTo('perform actions and see result');
$I->amOnPage('/');
$I->click('Sign Up!');
$I->seeCurrentUrlEquals('/register');
$I->fillField('Username:', 'JohnDoe');
$I->fillField('Email:', 'john@example.com');
$I->fillField('Password:', 'demo');
$I->fillField('Password Confirmation:', 'demo');
$I->click('Sign Up', 'input[type="submit"]');
$I->seeCurrentUrlEquals('');
$I->see('Welcome to Larabook');
$I->seeRecord('users', [
'username' => 'JohnDoe',
'email' => 'john@example.com'
]);
移植
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password', 60);
$table->string('remember_token')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
user.php的
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* Which fields may be mass assigned?
*
* @var array
*/
protected $fillable = ['username', 'name', 'password'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
RegistrationController.php
class RegistrationController extends \BaseController
{
/**
* Show a form to register a user.
*
* @return Response
*/
public function create()
{
return View::make('registration.create');
}
/**
* Create a new larabook user
*
* @return string
*/
public function store()
{
User::create(
Input::only('username', 'email', 'password')
);
return Redirect::home();
}
}
答案 0 :(得分:0)
看看你的User.php ..
/**
* Which fields may be mass assigned?
*
* @var array
*/
protected $fillable = ['username', 'name', 'password'];
应该是
protected $fillable = ['username', 'email', 'password'];