gpt4 book ai didi

php - Laravel - Larabook 教程 :Users. Codeception 确实看到了新记录

转载 作者:行者123 更新时间:2023-11-30 22:50:08 25 4
gpt4 key购买 nike

我无法通过 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');
}

}

用户.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');
}

注册 Controller .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();

}
}

最佳答案

看看你的 User.php..

/**
* Which fields may be mass assigned?
*
* @var array
*/
protected $fillable = ['username', 'name', 'password'];

应该是

protected $fillable = ['username', 'email', 'password'];

关于php - Laravel - Larabook 教程 :Users. Codeception 确实看到了新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28400147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com