使用数组名称输入的Laravel单元测试

时间:2016-07-05 12:34:06

标签: php unit-testing laravel phpunit laravel-5.2

输入我想填写:

<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 ""

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,找不到比

更好的解决方案
// 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');
}