【发布时间】:2017-02-01 21:03:45
【问题描述】:
我想在 Laravel 中测试我的注册表单。我正在这样做:
$this->visit('/auth/signup/free')
->type('First Name', 'first_name')
->type('test-phpunit@example.org', 'email')
->type('mypassword', 'password')
->press('Get Started');
但是我有一个错误 500,因为我将用户重定向到一个欢迎页面,该页面测试当前用户的某些属性,而这些属性不存在:
A request to [http://localhost/welcome] failed. Received status code [500].
Caused by
exception 'ErrorException' with message 'Undefined property: App\Models\User::$active' in D:\workspace\myproject\app\Models\User.php:48
Stack trace:
#0 D:\workspace\myproject\app\Models\User.php(48): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined prope...', 'D:\\workspace\\my...', 48, Array)
#1 D:\workspace\myproject\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2670): App\Models\User->active()
[...]
用户出现在数据库中,但 Laravel 似乎无权访问其任何属性。
我该如何处理?
编辑:我使用的是 Laravel 5.3。我和这个人有同样的错误:https://laracasts.com/discuss/channels/testing/51-phpunit-tests-fail-without-middleware/replies/89708
【问题讨论】:
-
你使用的是什么版本的 Laravel?
-
我使用的是 Laravel 5.3。
标签: php laravel unit-testing