尝试调用 press()
时方法,我总是得到
InvalidArgumentException: Unreachable field ""
在那条线上。
根据文档:
"Press" a button with the given text or name.
我的方法:
press('Create')
我的按钮是
<button class="btn btn-lg btn-primary" type="submit" name="submit">Create</button>
我也尝试过使用 name
结果相同。
我也试过submitForm('Create')
哪个有效,然后seeInDatabase('employees', ['email' => 'john@email.com'])
总是失败。
Unable to find row in database table [employees] that matched attributes [{"email":"john@email.com"}].
这是我的完整方法
public function testExample()
{
$this->actingAs(\App\Employee::where('username', 'grant')->first())
->visit('/employees/create')
->type('john', 'username')
->type('1234', 'password')
->type('john@email.com', 'email')
->submitForm('Create')
->seeInDatabase('employees', ['email' => 'john@email.com'])
->see('Employee Directory');
}
更新 1
这是我的表格:
{!! Form::open(['route' => 'employees.store', 'method' => 'POST']) !!}
@include('employees.form')
{!! Form::close() !!}
如您所见,我的字段不可能位于表单之外。
最佳答案
我不确定您的问题的确切原因是什么,但可能有多种原因。 我会发表评论,但我还没有足够的声誉。
首先,您是否通过验证器运行了纯 html?如果它给您任何语法错误,请尝试修复它们并再次运行单元测试。 (你可以试试这个 https://validator.w3.org/ ,只需复制并粘贴你的 html)
另一个原因可能是您有一些修改 DOM 的 javascript,而 Laravel 测试无法处理它。
最后,您可以尝试设置 <button>
的“值”属性去“创造”
<button class="btn btn-lg btn-primary" type="submit" name="submit" value="Create">Create</button>
或更改 <button>
到<input>
与 type
属性 "submit"
和 value
至 "Create"
<input type="submit" class="btn btn-lg btn-primary" name="submit" value="Create" />
关于php - Laravel 5.1 PHPUnit - press() 给我 'Unreachable field ""',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010792/