3

What is the right way to test this form with query_builder's anonymous function?

use Doctrine\ORM\EntityRepository;
// ...

$builder->add('users', 'entity', array(
    'class' => 'AcmeHelloBundle:User',
    'query_builder' => function(EntityRepository $er) {
        return $er->createQueryBuilder('u')
            ->orderBy('u.username', 'ASC');
    },
));

1 Answers1

0

PHPSpec is really for designing/testing your public API, so I think this would be better approached as an integration/acceptance test. You would never explicitly call your form's buildForm() method (it would be done by the form library) and the actual query would be executed during the relevant form event(s). In order to test this explicitly, you would have to test a lot of things which are within the forms library, and the rule is "don't test what you don't own".

Damon Jones
  • 219
  • 1
  • 3