This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form/Tests/AbstractFormTest.php

114 lines
3.1 KiB
PHP
Raw Normal View History

<?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.
*/
namespace Symfony\Component\Form\Tests;
2017-02-08 07:24:27 +00:00
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2017-02-08 07:24:27 +00:00
abstract class AbstractFormTest extends TestCase
{
/**
* @var EventDispatcherInterface
*/
protected $dispatcher;
/**
* @var \Symfony\Component\Form\FormFactoryInterface
*/
protected $factory;
/**
* @var \Symfony\Component\Form\FormInterface
*/
protected $form;
protected function setUp()
{
// We need an actual dispatcher to use the deprecated
// 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();
$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
*
* @return FormBuilder
*/
protected function getBuilder($name = 'name', EventDispatcherInterface $dispatcher = null, $dataClass = null, array $options = array())
{
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
}
/**
2014-11-30 13:33:44 +00:00
* @param string $name
*
* @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();
$form->expects($this->any())
->method('getName')
->will($this->returnValue($name));
$form->expects($this->any())
->method('getConfig')
->will($this->returnValue($config));
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();
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getDataTransformer()
{
2016-12-19 09:02:29 +00:00
return $this->getMockBuilder('Symfony\Component\Form\DataTransformerInterface')->getMock();
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getFormValidator()
{
2016-12-19 09:02:29 +00:00
return $this->getMockBuilder('Symfony\Component\Form\FormValidatorInterface')->getMock();
}
}