Ошибка PhpSpec при тестировании формы Symfony2 для выбора значений

У меня возникла проблема при написании PhpSpec для моей формы Symfony. Это ошибка, которую выдает PhpSpec при запуске спецификации.

Когда я закомментирую displayMode поле в моей форме, и спецификация, спецификация работает нормально.

  46  ! builds form with file field
        method call:
          - add("displayMode", "choice", ["label" => "Display Mode", "choices" => ["st_andrews" => "St Andrews", "ayr_belleisle" => "Ayr Belleisle"]])
        on Double\Symfony\Component\Form\FormBuilder\P1 was not expected, expected calls were:
          - getFormFactory()
          - addEventSubscriber(type(Sylius\Bundle\TaxonomyBundle\Form\EventListener\BuildTaxonFormSubscriber))
          - add(exact("translations"), exact("a2lix_translationsForms"), *)
          - add(exact("file"), exact("crmpicco_media_file"), exact(["label" => "Course Image"]))
          - add(exact("displayMode"), exact("choice"), exact(["label" => "Course Image", "choices" => ["st_andrews" => "St Andrews", "ayr_belleisle" => "Ayr Belleisle"]]))
          - remove(exact("file"))

----  broken examples

Это моя спецификация:

function it_builds_form(FormBuilder $builder, FormFactoryInterface $factory)
{
    $builder->getFormFactory()->willReturn($factory);

    $builder
        ->addEventSubscriber(
            Argument::type('Sylius\Bundle\TaxonomyBundle\Form\EventListener\BuildTaxonFormSubscriber')
        )
        ->willReturn($builder);

    $builder
        ->add('translations', 'a2lix_translationsForms', Argument::any())
        ->willReturn($builder);


    $builder->add('file', 'crmpicco_media_file', array('label' => 'Course Image'))->shouldBeCalled();
    $builder->add('displayMode', 'choice',
        array(
            'label' => 'Display Mode',
            'choices' => Course::getAvailableDisplayModes()
        ))->shouldBeCalled();
    $builder->remove('file')->shouldBeCalled();

    $this->buildForm($builder, array());
}

Это мой класс формы:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);

    // remove the standard image upload
    $builder->remove('file');

    // ...then add the custom asset file/image upload
    $builder
        ->add('displayMode', 'choice', array(
            'label'   => 'Display Mode',
            'choices' => Course::getAvailableDisplayModes()
        ))
        ->add('file', 'crmpicco_media_file', array(
            'label' => 'Course Image'
        ));
}

1 ответ

Решение

Возможно, вы уже заметили это, но в вашем примере спецификации:

$builder->add('displayMode', 'choice', [
    'label' => 'Course Image',
     //...
])->shouldBeCalled();

не должно ли это быть...?

$builder->add('displayMode', 'choice', [
    'label' => 'Display Mode',
     //...
])->shouldBeCalled();
Другие вопросы по тегам