Skip to content

Commit 9093b33

Browse files
Merge branch '3.4' into 4.2
* 3.4: Remove "internal" annotation from datacollector serialization methods replace mocks with real objects in tests Fix phpunit 8 compatibility render integer types with grouping as text input ignore _method forms in NativeRequestHandler don't lose int precision with not needed type casts
2 parents 98cabc9 + 547e54e commit 9093b33

29 files changed

+529
-470
lines changed

Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ public function reverseTransform($value)
4646

4747
return null !== $result ? (int) $result : null;
4848
}
49+
50+
/**
51+
* @internal
52+
*/
53+
protected function castParsedValue($value)
54+
{
55+
return $value;
56+
}
4957
}

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ public function reverseTransform($value)
181181
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
182182
}
183183

184-
if (\is_int($result) && $result === (int) $float = (float) $result) {
185-
$result = $float;
186-
}
184+
$result = $this->castParsedValue($result);
187185

188186
if (false !== $encoding = mb_detect_encoding($value, null, true)) {
189187
$length = mb_strlen($value, $encoding);
@@ -228,6 +226,18 @@ protected function getNumberFormatter()
228226
return $formatter;
229227
}
230228

229+
/**
230+
* @internal
231+
*/
232+
protected function castParsedValue($value)
233+
{
234+
if (\is_int($value) && $value === (int) $float = (float) $value) {
235+
return $float;
236+
}
237+
238+
return $value;
239+
}
240+
231241
/**
232242
* Rounds a number according to the configured scale and rounding mode.
233243
*

Extension/Core/Type/IntegerType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
1616
use Symfony\Component\Form\FormBuilderInterface;
17+
use Symfony\Component\Form\FormInterface;
18+
use Symfony\Component\Form\FormView;
1719
use Symfony\Component\OptionsResolver\OptionsResolver;
1820

1921
class IntegerType extends AbstractType
@@ -26,6 +28,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2628
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
2729
}
2830

31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function buildView(FormView $view, FormInterface $form, array $options)
35+
{
36+
if ($options['grouping']) {
37+
$view->vars['type'] = 'text';
38+
}
39+
}
40+
2941
/**
3042
* {@inheritdoc}
3143
*/

Extension/DataCollector/FormDataCollector.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ public function getData()
229229
return $this->data;
230230
}
231231

232-
/**
233-
* @internal
234-
*/
235232
public function serialize()
236233
{
237234
foreach ($this->data['forms_by_hash'] as &$form) {

NativeRequestHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public function handleRequest(FormInterface $form, $request = null)
115115
return;
116116
}
117117

118+
if (\is_array($data) && array_key_exists('_method', $data) && $method === $data['_method'] && !$form->has('_method')) {
119+
unset($data['_method']);
120+
}
121+
118122
$form->submit($data, 'PATCH' !== $method);
119123
}
120124

Tests/AbstractLayoutTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,21 @@ public function testInteger()
17961796
);
17971797
}
17981798

1799+
public function testIntegerTypeWithGroupingRendersAsTextInput()
1800+
{
1801+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 123, [
1802+
'grouping' => true,
1803+
]);
1804+
1805+
$this->assertWidgetMatchesXpath($form->createView(), [],
1806+
'/input
1807+
[@type="text"]
1808+
[@name="name"]
1809+
[@value="123"]
1810+
'
1811+
);
1812+
}
1813+
17991814
public function testLanguage()
18001815
{
18011816
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\LanguageType', 'de');

Tests/AbstractRequestHandlerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testMergeParamsAndFiles($method)
200200
$form = $this->createForm('param1', $method, true);
201201
$form->add($this->createForm('field1'));
202202
$form->add($this->createBuilder('field2', false, ['allow_file_upload' => true])->getForm());
203-
$file = $this->getMockFile();
203+
$file = $this->getUploadedFile();
204204

205205
$this->setRequestData($method, [
206206
'param1' => [
@@ -225,7 +225,7 @@ public function testMergeParamsAndFiles($method)
225225
public function testParamTakesPrecedenceOverFile($method)
226226
{
227227
$form = $this->createForm('param1', $method);
228-
$file = $this->getMockFile();
228+
$file = $this->getUploadedFile();
229229

230230
$this->setRequestData($method, [
231231
'param1' => 'DATA',
@@ -247,7 +247,7 @@ public function testSubmitFileIfNoParam($method)
247247
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
248248
->setMethod($method)
249249
->getForm();
250-
$file = $this->getMockFile();
250+
$file = $this->getUploadedFile();
251251

252252
$this->setRequestData($method, [
253253
'param1' => null,
@@ -269,14 +269,14 @@ public function testSubmitMultipleFiles($method)
269269
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
270270
->setMethod($method)
271271
->getForm();
272-
$file = $this->getMockFile();
272+
$file = $this->getUploadedFile();
273273

274274
$this->setRequestData($method, [
275275
'param1' => null,
276276
], [
277-
'param2' => $this->getMockFile('2'),
277+
'param2' => $this->getUploadedFile('2'),
278278
'param1' => $file,
279-
'param3' => $this->getMockFile('3'),
279+
'param3' => $this->getUploadedFile('3'),
280280
]);
281281

282282
$this->requestHandler->handleRequest($form, $this->request);
@@ -332,7 +332,7 @@ public function getPostMaxSizeFixtures()
332332

333333
public function testUploadedFilesAreAccepted()
334334
{
335-
$this->assertTrue($this->requestHandler->isFileUpload($this->getMockFile()));
335+
$this->assertTrue($this->requestHandler->isFileUpload($this->getUploadedFile()));
336336
}
337337

338338
public function testInvalidFilesAreRejected()
@@ -344,7 +344,7 @@ abstract protected function setRequestData($method, $data, $files = []);
344344

345345
abstract protected function getRequestHandler();
346346

347-
abstract protected function getMockFile($suffix = '');
347+
abstract protected function getUploadedFile($suffix = '');
348348

349349
abstract protected function getInvalidFile();
350350

Tests/DependencyInjection/FormPassTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
use Symfony\Component\DependencyInjection\ServiceLocator;
2121
use Symfony\Component\Form\AbstractType;
2222
use Symfony\Component\Form\AbstractTypeExtension;
23+
use Symfony\Component\Form\Command\DebugCommand;
2324
use Symfony\Component\Form\DependencyInjection\FormPass;
24-
use Symfony\Component\Form\FormRegistryInterface;
25+
use Symfony\Component\Form\FormRegistry;
2526

2627
/**
2728
* @author Bernhard Schussek <[email protected]>
@@ -71,8 +72,12 @@ public function testAddTaggedTypesToDebugCommand()
7172
{
7273
$container = $this->createContainerBuilder();
7374

75+
$container->register('form.registry', FormRegistry::class);
76+
$commandDefinition = new Definition(DebugCommand::class, [new Reference('form.registry')]);
77+
$commandDefinition->setPublic(true);
78+
7479
$container->setDefinition('form.extension', $this->createExtensionDefinition());
75-
$container->setDefinition('console.command.form_debug', $this->createDebugCommandDefinition());
80+
$container->setDefinition('console.command.form_debug', $commandDefinition);
7681
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type')->setPublic(true);
7782
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type')->setPublic(true);
7883

@@ -379,19 +384,6 @@ private function createExtensionDefinition()
379384
return $definition;
380385
}
381386

382-
private function createDebugCommandDefinition()
383-
{
384-
$definition = new Definition('Symfony\Component\Form\Command\DebugCommand');
385-
$definition->setPublic(true);
386-
$definition->setArguments([
387-
$formRegistry = $this->getMockBuilder(FormRegistryInterface::class)->getMock(),
388-
[],
389-
['Symfony\Component\Form\Extension\Core\Type'],
390-
]);
391-
392-
return $definition;
393-
}
394-
395387
private function createContainerBuilder()
396388
{
397389
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)