Skip to content

Commit 11dcf08

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [Validator] Add missing vietnamese translations add German translation [Validator][ConstraintValidator] Update wrong PRETTY_DATE doc [DomCrawler][Form] Fix PHPDoc on get & offsetGet prevent method calls on null values Return int if scale = 0
2 parents caa6157 + 5ea08fe commit 11dcf08

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function remove($name)
279279
*
280280
* @param string $name The field name
281281
*
282-
* @return FormField The field instance
282+
* @return FormField|FormField[]|FormField[][] The value of the field
283283
*
284284
* @throws \InvalidArgumentException When field is not present in this form
285285
*/
@@ -323,7 +323,7 @@ public function offsetExists($name)
323323
*
324324
* @param string $name The field name
325325
*
326-
* @return FormField The associated Field instance
326+
* @return FormField|FormField[]|FormField[][] The value of the field
327327
*
328328
* @throws \InvalidArgumentException if the field does not exist
329329
*/

FormFieldRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function remove(string $name)
6666
/**
6767
* Returns the value of the field based on the fully qualifed name and its children.
6868
*
69-
* @return mixed The value of the field
69+
* @return FormField|FormField[]|FormField[][] The value of the field
7070
*
7171
* @throws \InvalidArgumentException if the field does not exist
7272
*/

Tests/FormTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DomCrawler\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DomCrawler\Field\TextareaFormField;
1516
use Symfony\Component\DomCrawler\Form;
1617
use Symfony\Component\DomCrawler\FormFieldRegistry;
1718

@@ -965,7 +966,7 @@ protected function createTestMultipleForm()
965966
return $dom;
966967
}
967968

968-
public function testgetPhpValuesWithEmptyTextarea()
969+
public function testGetPhpValuesWithEmptyTextarea()
969970
{
970971
$dom = new \DOMDocument();
971972
$dom->loadHTML('
@@ -980,4 +981,34 @@ public function testgetPhpValuesWithEmptyTextarea()
980981
$form = new Form($nodes->item(0), 'http://example.com');
981982
$this->assertEquals($form->getPhpValues(), ['example' => '']);
982983
}
984+
985+
public function testGetReturnTypes()
986+
{
987+
$dom = new \DOMDocument();
988+
$dom->loadHTML('
989+
<html>
990+
<form>
991+
<textarea name="foo[collection][0][bar]">item 0</textarea>
992+
</form>
993+
</html>'
994+
);
995+
996+
$nodes = $dom->getElementsByTagName('form');
997+
$form = new Form($nodes->item(0), 'http://example.com');
998+
999+
// FormField
1000+
$this->assertInstanceOf(TextareaFormField::class, $textareaFormField = $form->get('foo[collection][0][bar]'));
1001+
1002+
// Array of FormField
1003+
$this->assertSame([
1004+
'bar' => $textareaFormField,
1005+
], $form->get('foo[collection][0]'));
1006+
1007+
// Array of array of FormField
1008+
$this->assertSame([
1009+
[
1010+
'bar' => $textareaFormField,
1011+
],
1012+
], $form->get('foo[collection]'));
1013+
}
9831014
}

0 commit comments

Comments
 (0)