feature #10569 [Form] Accept interfaces to be passed to "data_class" (webmozart)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Form] Accept interfaces to be passed to "data_class" | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8669 | License | MIT | Doc PR | - Commits -------b44e07b
[Form] Added test case for 4759e062ed004749dbdc2ba31aef0f8ac26018957bc7a8a
[Form] Accept interfaces to be passed to "data_class"
This commit is contained in:
commit
880880b838
@ -14,6 +14,7 @@ CHANGELOG
|
||||
* errors mapped to unsubmitted forms are discarded now
|
||||
* ObjectChoiceList now compares choices by their value, if a value path is
|
||||
given
|
||||
* you can now pass interface names in the "data_class" option
|
||||
|
||||
2.4.0
|
||||
-----
|
||||
|
@ -192,7 +192,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
|
||||
{
|
||||
self::validateName($name);
|
||||
|
||||
if (null !== $dataClass && !class_exists($dataClass)) {
|
||||
if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass)) {
|
||||
throw new InvalidArgumentException(sprintf('The data class "%s" is not a valid class.', $dataClass));
|
||||
}
|
||||
|
||||
|
@ -146,6 +146,37 @@ class FormTypeTest extends BaseTypeTest
|
||||
$this->assertSame(10, $view->vars['attr']['maxlength']);
|
||||
}
|
||||
|
||||
public function testDataClassMayBeNull()
|
||||
{
|
||||
$this->factory->createBuilder('form', null, array(
|
||||
'data_class' => null,
|
||||
));
|
||||
}
|
||||
|
||||
public function testDataClassMayBeAbstractClass()
|
||||
{
|
||||
$this->factory->createBuilder('form', null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
|
||||
));
|
||||
}
|
||||
|
||||
public function testDataClassMayBeInterface()
|
||||
{
|
||||
$this->factory->createBuilder('form', null, array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testDataClassMustBeValidClassOrInterface()
|
||||
{
|
||||
$this->factory->createBuilder('form', null, array(
|
||||
'data_class' => 'foobar',
|
||||
));
|
||||
}
|
||||
|
||||
public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable()
|
||||
{
|
||||
$builder = $this->factory->createBuilder('form', null, array(
|
||||
|
16
src/Symfony/Component/Form/Tests/Fixtures/AbstractAuthor.php
Normal file
16
src/Symfony/Component/Form/Tests/Fixtures/AbstractAuthor.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Fixtures;
|
||||
|
||||
abstract class AbstractAuthor
|
||||
{
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 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\Fixtures;
|
||||
|
||||
interface AuthorInterface
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user