Laravel 使用数组名称输入的单元测试
Laravel unit test with input with array name
我要填写的输入:
<input type="text" id="order-number" name="order_numbers[]" class="form-control">
我的单元测试代码:
public function testSearch()
{
$this->actAsUser();
$this->visit('/orders')
->type('12001546', 'order_numbers[]');
}
我得到的错误:
1) OrdersTest::testSearch
InvalidArgumentException: Unreachable field ""
我遇到了同样的问题,找不到比
更好的解决方案
// TestCase.php
protected function storeArrayInput($values, $name)
{
$this->inputs[$name] = $values;
return $this;
}
// YourTest.php
public function testSearch()
{
$this->actAsUser();
$this->visit('/orders')
->storeArrayInput(['12001546'], 'order_numbers');
}
我要填写的输入:
<input type="text" id="order-number" name="order_numbers[]" class="form-control">
我的单元测试代码:
public function testSearch()
{
$this->actAsUser();
$this->visit('/orders')
->type('12001546', 'order_numbers[]');
}
我得到的错误:
1) OrdersTest::testSearch
InvalidArgumentException: Unreachable field ""
我遇到了同样的问题,找不到比
更好的解决方案// TestCase.php
protected function storeArrayInput($values, $name)
{
$this->inputs[$name] = $values;
return $this;
}
// YourTest.php
public function testSearch()
{
$this->actAsUser();
$this->visit('/orders')
->storeArrayInput(['12001546'], 'order_numbers');
}