2012-07-06 14:33:06 +01:00
|
|
|
<?php
|
|
|
|
|
2015-03-26 22:32:35 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
2012-07-06 14:33:06 +01:00
|
|
|
|
|
|
|
namespace Symfony\Component\Form\Tests;
|
|
|
|
|
|
|
|
use Symfony\Component\Form\FormBuilder;
|
2012-07-09 19:34:45 +01:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
2012-07-06 14:33:06 +01:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
|
|
|
|
abstract class AbstractFormTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var EventDispatcherInterface
|
|
|
|
*/
|
|
|
|
protected $dispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Form\FormFactoryInterface
|
|
|
|
*/
|
|
|
|
protected $factory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Form\FormInterface
|
|
|
|
*/
|
|
|
|
protected $form;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2012-08-28 14:24:45 +01:00
|
|
|
$this->dispatcher = new EventDispatcher();
|
2012-07-06 14:33:06 +01:00
|
|
|
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
|
|
|
|
$this->form = $this->createForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->dispatcher = null;
|
|
|
|
$this->factory = null;
|
|
|
|
$this->form = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Symfony\Component\Form\FormInterface
|
|
|
|
*/
|
|
|
|
abstract protected function createForm();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param EventDispatcherInterface $dispatcher
|
|
|
|
* @param string $dataClass
|
2013-11-16 15:13:54 +00:00
|
|
|
* @param array $options
|
2012-07-06 14:33:06 +01:00
|
|
|
*
|
|
|
|
* @return FormBuilder
|
|
|
|
*/
|
2013-09-17 10:39:17 +01:00
|
|
|
protected function getBuilder($name = 'name', EventDispatcherInterface $dispatcher = null, $dataClass = null, array $options = array())
|
2012-07-06 14:33:06 +01:00
|
|
|
{
|
2013-09-17 10:39:17 +01:00
|
|
|
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
|
2012-07-06 14:33:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param string $name
|
2012-07-06 14:33:06 +01:00
|
|
|
*
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getMockForm($name = 'name')
|
|
|
|
{
|
2012-12-17 08:01:30 +00:00
|
|
|
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
2013-04-29 16:31:30 +01:00
|
|
|
$config = $this->getMock('Symfony\Component\Form\FormConfigInterface');
|
2012-07-06 14:33:06 +01:00
|
|
|
|
|
|
|
$form->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->will($this->returnValue($name));
|
2013-04-29 16:31:30 +01:00
|
|
|
$form->expects($this->any())
|
|
|
|
->method('getConfig')
|
|
|
|
->will($this->returnValue($config));
|
2012-07-06 14:33:06 +01:00
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getDataMapper()
|
|
|
|
{
|
|
|
|
return $this->getMock('Symfony\Component\Form\DataMapperInterface');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getDataTransformer()
|
|
|
|
{
|
|
|
|
return $this->getMock('Symfony\Component\Form\DataTransformerInterface');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getFormValidator()
|
|
|
|
{
|
|
|
|
return $this->getMock('Symfony\Component\Form\FormValidatorInterface');
|
|
|
|
}
|
|
|
|
}
|