title: Symfony2 Unit Testing Forms with constraints
body: <p>I've got a form which isn't connected to a entity but does have constraints like mentioned in here: <a href="http://symfony.com/doc/current/book/forms.html#adding-validation" rel="noreferrer">http://symfony.com/doc/current/book/forms.html#adding-validation</a></p>
  
  <blockquote>
    <p>ContactBundle\Tests\Form\Type\TestedTypeTest::testSubmitValidData
    Symfony\Component\OptionsResolver\Exception\InvalidOptionsException: The option "constraints" does not exist. Known options are: "action", "attr", "auto_initialize", "block_name", "by_reference", "compound", "data", "data_class", "disabled", "empty_data", "error_bubbling", "inherit_data", "label", "label_attr", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "virtual"</p>
  </blockquote>
  
  <p>Here is part of the form:</p>
  
  <pre><code>class ContactType extends AbstractType
  {
  
  /**
   * Build the form
   * @param \Symfony\Component\Form\FormBuilderInterface $builder BuilderInterface
   * @param array $aOption Array of options
   */
  public function buildForm(FormBuilderInterface $builder, array $aOption)
  {
      ///..
      $builder-&gt;add('name', 'text', array(
                  'constraints' =&gt; array(
                      new NotBlank(),
                      new Length(array('min' =&gt; 3)),
                  ),
              ))
              -&gt;add('address', 'textarea', array(
                  'required' =&gt; false
              ))
              //..
              ;
      //..
  </code></pre>
  
  <p>Here is the unit test</p>
  
  <pre><code>class TestedTypeTest extends TypeTestCase
  {
  
  public function testSubmitValidData()
  {
      $formData = array(
          'name' =&gt; 'Test Name',
          'address' =&gt; '',
      );
      $type = new ContactType();
      $form = $this-&gt;factory-&gt;create($type, $formData);
      $form-&gt;submit($formData);
  
      $this-&gt;assertTrue($form-&gt;isSynchronized());
  
      $view = $form-&gt;createView();
      $children = $view-&gt;children;
  
      foreach (array_keys($formData) as $key) {
          $this-&gt;assertArrayHasKey($key, $children);
      }
  }
  }
  </code></pre>
  
  <p>I'm guessing that this is a problem with the test instead of the form as the form works as expected. I'm not sure what I should change.
  Any help or advice would be handy</p>
  
  <p>Thanks</p>