Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdb419e

Browse files
Merge branch '2.8'
* 2.8: Fix BC for the default root form name Conflicts: src/Symfony/Component/Form/FormFactory.php src/Symfony/Component/Form/Tests/FormFactoryTest.php
2 parents f20f2f0 + b48bbb8 commit fdb419e

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/Symfony/Component/Form/FormFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Typ
6565
throw new UnexpectedTypeException($type, 'string');
6666
}
6767

68-
return $this->createNamedBuilder(StringUtil::fqcnToBlockPrefix($type), $type, $data, $options);
68+
if (null === $name = $this->registry->getType($type)->getBlockPrefix()) {
69+
$name = StringUtil::fqcnToBlockPrefix($type);
70+
}
71+
72+
return $this->createNamedBuilder($name, $type, $data, $options);
6973
}
7074

7175
/**

src/Symfony/Component/Form/Tests/FormFactoryTest.php

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,52 @@ public function testCreateThrowsUnderstandableException()
169169
$this->factory->create(new \stdClass());
170170
}
171171

172+
public function testCreateUsesBlockPrefixIfTypeGivenAsString()
173+
{
174+
$options = array('a' => '1', 'b' => '2');
175+
$resolvedOptions = array('a' => '2', 'b' => '3');
176+
177+
// the interface does not have the method, so use the real class
178+
$resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
179+
->disableOriginalConstructor()
180+
->getMock();
181+
182+
$resolvedType->expects($this->any())
183+
->method('getBlockPrefix')
184+
->willReturn('TYPE_PREFIX');
185+
186+
$this->registry->expects($this->any())
187+
->method('getType')
188+
->with('TYPE')
189+
->will($this->returnValue($resolvedType));
190+
191+
$resolvedType->expects($this->once())
192+
->method('createBuilder')
193+
->with($this->factory, 'TYPE_PREFIX', $options)
194+
->will($this->returnValue($this->builder));
195+
196+
$this->builder->expects($this->any())
197+
->method('getOptions')
198+
->will($this->returnValue($resolvedOptions));
199+
200+
$resolvedType->expects($this->once())
201+
->method('buildForm')
202+
->with($this->builder, $resolvedOptions);
203+
204+
$this->builder->expects($this->once())
205+
->method('getForm')
206+
->will($this->returnValue('FORM'));
207+
208+
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
209+
}
210+
172211
public function testCreateUsesTypeNameIfTypeGivenAsString()
173212
{
174213
$options = array('a' => '1', 'b' => '2');
175214
$resolvedOptions = array('a' => '2', 'b' => '3');
176215
$resolvedType = $this->getMockResolvedType();
177216

178-
$this->registry->expects($this->once())
217+
$this->registry->expects($this->any())
179218
->method('getType')
180219
->with('TYPE')
181220
->will($this->returnValue($resolvedType));
@@ -206,7 +245,7 @@ public function testCreateStripsNamespaceOffTypeName()
206245
$resolvedOptions = array('a' => '2', 'b' => '3');
207246
$resolvedType = $this->getMockResolvedType();
208247

209-
$this->registry->expects($this->once())
248+
$this->registry->expects($this->any())
210249
->method('getType')
211250
->with('Vendor\Name\Space\UserForm')
212251
->will($this->returnValue($resolvedType));
@@ -237,7 +276,7 @@ public function testCreateStripsTypeSuffixOffTypeName()
237276
$resolvedOptions = array('a' => '2', 'b' => '3');
238277
$resolvedType = $this->getMockResolvedType();
239278

240-
$this->registry->expects($this->once())
279+
$this->registry->expects($this->any())
241280
->method('getType')
242281
->with('Vendor\Name\Space\UserType')
243282
->will($this->returnValue($resolvedType));
@@ -268,7 +307,7 @@ public function testCreateDoesNotStripTypeSuffixIfResultEmpty()
268307
$resolvedOptions = array('a' => '2', 'b' => '3');
269308
$resolvedType = $this->getMockResolvedType();
270309

271-
$this->registry->expects($this->once())
310+
$this->registry->expects($this->any())
272311
->method('getType')
273312
->with('Vendor\Name\Space\Type')
274313
->will($this->returnValue($resolvedType));
@@ -299,7 +338,7 @@ public function testCreateConvertsTypeToUnderscoreSyntax()
299338
$resolvedOptions = array('a' => '2', 'b' => '3');
300339
$resolvedType = $this->getMockResolvedType();
301340

302-
$this->registry->expects($this->once())
341+
$this->registry->expects($this->any())
303342
->method('getType')
304343
->with('Vendor\Name\Space\MyProfileHTMLType')
305344
->will($this->returnValue($resolvedType));

0 commit comments

Comments
 (0)