2015-06-30 28 views
0

我正在將我的symfony2應用程序傳遞給PHPUnit,並且我在表單測試中遇到了一些問題。在我的表單中,我有一個choice名單,我通過從選項控制器陣列通過填補了這一名單與$options這樣的:

//Controller 
$form = $this->createForm(new AdddocType(), array(
    'docdata' => $myarray, 
)); 

//Form 
->add('myfield', 'choice', array(
    'choices' => $options['data']['docdata'], 
    'multiple' => false, 
    'required' => true, 
    'expanded' => false, 
)) 

在這裏,我PHPUnit的測試:

public function testaddContact() 
{ 
    $formData = array(
     'myfield' => 10, 
     ... 
     ... 
    ); 

    $type = new AdddocType(); 
    $form = $this->factory->create($type); 
    $form->submit($formData); 

    $this->assertTrue($form->isSynchronized()); 
} 

當我通過PHPUnit的,在這行代碼停在我的formType:

'choices' => $options['data']['docdata'], 

我的問題是:我怎麼能傳遞我PHPUnit的測試$options

感謝

回答

0

選項可以在create()第三個參數傳遞。不難發現...