2016-07-05 15 views
0

輸入我試圖填補:與陣列輸入Laravel單元測試名稱

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

怎麼樣'類型( '12001546', 'product_ids []')''未ORDER_NUMBER []'? – ishadif

+0

對不起,我在第一篇文章中有錯誤的元素,改變了它,並修復了導致新錯誤的單元測試代碼中的錯字。 – user3482304

回答

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'); 
} 
+0

非常感謝,這工作。 – user3482304