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;
|
|
|
|
|
2017-02-08 07:24:27 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2012-07-06 14:33:06 +01:00
|
|
|
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;
|
|
|
|
|
2017-02-08 07:24:27 +00:00
|
|
|
abstract class AbstractFormTest extends TestCase
|
2012-07-06 14:33:06 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var EventDispatcherInterface
|
|
|
|
*/
|
|
|
|
protected $dispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Form\FormFactoryInterface
|
|
|
|
*/
|
|
|
|
protected $factory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Form\FormInterface
|
|
|
|
*/
|
|
|
|
protected $form;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2013-04-20 16:32:55 +01:00
|
|
|
// We need an actual dispatcher to use the deprecated
|
2012-07-09 19:34:45 +01:00
|
|
|
// bindRequest() method
|
2012-08-28 14:24:45 +01:00
|
|
|
$this->dispatcher = new EventDispatcher();
|
2016-12-19 09:02:29 +00:00
|
|
|
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
|
2012-07-06 14:33:06 +01:00
|
|
|
$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')
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
|
|
|
|
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();
|
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()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
return $this->getMockBuilder('Symfony\Component\Form\DataMapperInterface')->getMock();
|
2012-07-06 14:33:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getDataTransformer()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
return $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock();
|
2012-07-06 14:33:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function getFormValidator()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
return $this->getMockBuilder('Symfony\Component\Form\FormValidatorInterface')->getMock();
|
2012-07-06 14:33:06 +01:00
|
|
|
}
|
|
|
|
}
|