CompoundFormPerformanceTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Tests;
  11. use Symfony\Component\Form\Test\FormPerformanceTestCase;
  12. /**
  13. * @author Bernhard Schussek <bschussek@gmail.com>
  14. */
  15. class CompoundFormPerformanceTest extends FormPerformanceTestCase
  16. {
  17. /**
  18. * Create a compound form multiple times, as happens in a collection form.
  19. *
  20. * @group benchmark
  21. */
  22. public function testArrayBasedForm()
  23. {
  24. $this->setMaxRunningTime(1);
  25. for ($i = 0; $i < 40; ++$i) {
  26. $form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
  27. ->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
  28. ->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
  29. ->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
  30. 'choices' => array('male' => 'Male', 'female' => 'Female'),
  31. 'required' => false,
  32. ))
  33. ->add('age', 'Symfony\Component\Form\Extension\Core\Type\NumberType')
  34. ->add('birthDate', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType')
  35. ->add('city', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
  36. // simulate 300 different cities
  37. 'choices' => range(1, 300),
  38. ))
  39. ->getForm();
  40. // load the form into a view
  41. $form->createView();
  42. }
  43. }
  44. }