Skip to content

Commit b5e0994

Browse files
committed
Merge branch '5.0'
* 5.0: [Dotenv] Documentation improvement [DI] Clarified deprecation for TypedReference in 4.4 [Validator] Add missing vietnamese translations add German translation add missing Messenger options to XML schema definition [5.0] Remove some unused variables [Validator][ConstraintValidator] Update wrong PRETTY_DATE doc [DomCrawler][Form] Fix PHPDoc on get & offsetGet [ErrorHandler] fix parsing static return type on interface method annotation (fix #35836) prevent method calls on null values Return int if scale = 0
2 parents f2e6e7b + 4368bdd commit b5e0994

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
@@ -273,7 +273,7 @@ public function remove(string $name)
273273
/**
274274
* Gets a named field.
275275
*
276-
* @return FormField The field instance
276+
* @return FormField|FormField[]|FormField[][] The value of the field
277277
*
278278
* @throws \InvalidArgumentException When field is not present in this form
279279
*/
@@ -317,7 +317,7 @@ public function offsetExists($name)
317317
*
318318
* @param string $name The field name
319319
*
320-
* @return FormField The associated Field instance
320+
* @return FormField|FormField[]|FormField[][] The value of the field
321321
*
322322
* @throws \InvalidArgumentException if the field does not exist
323323
*/

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)