4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests
;
14 use Symfony\Component\Form\FormBuilder
;
15 use Symfony\Component\EventDispatcher\EventDispatcher
;
16 use Symfony\Component\EventDispatcher\EventDispatcherInterface
;
18 abstract class AbstractFormTest
extends \PHPUnit_Framework_TestCase
21 * @var EventDispatcherInterface
23 protected $dispatcher;
26 * @var \Symfony\Component\Form\FormFactoryInterface
31 * @var \Symfony\Component\Form\FormInterface
35 protected function setUp()
37 if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
38 $this->markTestSkipped('The "EventDispatcher" component is not available');
41 // We need an actual dispatcher to use the deprecated
42 // bindRequest() method
43 $this->dispatcher
= new EventDispatcher();
44 $this->factory
= $this->getMock('Symfony\Component\Form\FormFactoryInterface');
45 $this->form
= $this->createForm();
48 protected function tearDown()
50 $this->dispatcher
= null;
51 $this->factory
= null;
56 * @return \Symfony\Component\Form\FormInterface
58 abstract protected function createForm();
62 * @param EventDispatcherInterface $dispatcher
63 * @param string $dataClass
67 protected function getBuilder($name = 'name', EventDispatcherInterface
$dispatcher = null, $dataClass = null)
69 return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher
, $this->factory
);
75 * @return \PHPUnit_Framework_MockObject_MockObject
77 protected function getMockForm($name = 'name')
79 $form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
80 $config = $this->getMock('Symfony\Component\Form\FormConfigInterface');
82 $form->expects($this->any())
84 ->will($this->returnValue($name));
85 $form->expects($this->any())
87 ->will($this->returnValue($config));
95 * @return \PHPUnit_Framework_MockObject_MockObject
97 protected function getValidForm($name)
99 $form = $this->getMockForm($name);
101 $form->expects($this->any())
103 ->will($this->returnValue(true));
109 * @param string $name
111 * @return \PHPUnit_Framework_MockObject_MockObject
113 protected function getInvalidForm($name)
115 $form = $this->getMockForm($name);
117 $form->expects($this->any())
119 ->will($this->returnValue(false));
125 * @return \PHPUnit_Framework_MockObject_MockObject
127 protected function getDataMapper()
129 return $this->getMock('Symfony\Component\Form\DataMapperInterface');
133 * @return \PHPUnit_Framework_MockObject_MockObject
135 protected function getDataTransformer()
137 return $this->getMock('Symfony\Component\Form\DataTransformerInterface');
141 * @return \PHPUnit_Framework_MockObject_MockObject
143 protected function getFormValidator()
145 return $this->getMock('Symfony\Component\Form\FormValidatorInterface');