[Form] changed the way default type names are created to avoid collisions

This commit is contained in:
Fabien Potencier 2011-06-09 16:42:57 +02:00
parent f3cafcb355
commit d044498cde
2 changed files with 6 additions and 8 deletions

View File

@ -128,15 +128,13 @@ abstract class AbstractType implements FormTypeInterface
/**
* Returns the name of this type.
*
* The default name type is the class name without the Form nor Type suffix
* The default name type is the class name, where \ are replaced by _.
*
* @return string The name of this type
*/
public function getName()
{
preg_match('/\\\\(\w+?)(Form)?(Type)?$/i', get_class($this), $matches);
return strtolower($matches[1]);
return strtolower(str_replace('\\', '_', get_class($this)));
}
/**

View File

@ -19,28 +19,28 @@ class AbstractTypeTest extends \PHPUnit_Framework_TestCase
{
$type = new MyTest();
$this->assertEquals('mytest', $type->getName());
$this->assertEquals('symfony_tests_component_form_mytest', $type->getName());
}
public function testGetNameWithTypeSuffix()
{
$type = new MyTestType();
$this->assertEquals('mytest', $type->getName());
$this->assertEquals('symfony_tests_component_form_mytesttype', $type->getName());
}
public function testGetNameWithFormSuffix()
{
$type = new MyTestForm();
$this->assertEquals('mytest', $type->getName());
$this->assertEquals('symfony_tests_component_form_mytestform', $type->getName());
}
public function testGetNameWithFormTypeSuffix()
{
$type = new MyTestFormType();
$this->assertEquals('mytest', $type->getName());
$this->assertEquals('symfony_tests_component_form_mytestformtype', $type->getName());
}
}