Skip to content

Commit 5ea08fe

Browse files
committed
[DomCrawler][Form] Fix PHPDoc on get & offsetGet
1 parent 8540917 commit 5ea08fe

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
@@ -269,7 +269,7 @@ public function remove($name)
269269
*
270270
* @param string $name The field name
271271
*
272-
* @return FormField The field instance
272+
* @return FormField|FormField[]|FormField[][] The value of the field
273273
*
274274
* @throws \InvalidArgumentException When field is not present in this form
275275
*/
@@ -313,7 +313,7 @@ public function offsetExists($name)
313313
*
314314
* @param string $name The field name
315315
*
316-
* @return FormField The associated Field instance
316+
* @return FormField|FormField[]|FormField[][] The value of the field
317317
*
318318
* @throws \InvalidArgumentException if the field does not exist
319319
*/

FormFieldRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function remove($name)
7070
*
7171
* @param string $name The fully qualified name of the field
7272
*
73-
* @return mixed The value of the field
73+
* @return FormField|FormField[]|FormField[][] The value of the field
7474
*
7575
* @throws \InvalidArgumentException if the field does not exist
7676
*/

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

@@ -953,7 +954,7 @@ protected function createTestMultipleForm()
953954
return $dom;
954955
}
955956

956-
public function testgetPhpValuesWithEmptyTextarea()
957+
public function testGetPhpValuesWithEmptyTextarea()
957958
{
958959
$dom = new \DOMDocument();
959960
$dom->loadHTML('
@@ -968,4 +969,34 @@ public function testgetPhpValuesWithEmptyTextarea()
968969
$form = new Form($nodes->item(0), 'http://example.com');
969970
$this->assertEquals($form->getPhpValues(), ['example' => '']);
970971
}
972+
973+
public function testGetReturnTypes()
974+
{
975+
$dom = new \DOMDocument();
976+
$dom->loadHTML('
977+
<html>
978+
<form>
979+
<textarea name="foo[collection][0][bar]">item 0</textarea>
980+
</form>
981+
</html>'
982+
);
983+
984+
$nodes = $dom->getElementsByTagName('form');
985+
$form = new Form($nodes->item(0), 'http://example.com');
986+
987+
// FormField
988+
$this->assertInstanceOf(TextareaFormField::class, $textareaFormField = $form->get('foo[collection][0][bar]'));
989+
990+
// Array of FormField
991+
$this->assertSame([
992+
'bar' => $textareaFormField,
993+
], $form->get('foo[collection][0]'));
994+
995+
// Array of array of FormField
996+
$this->assertSame([
997+
[
998+
'bar' => $textareaFormField,
999+
],
1000+
], $form->get('foo[collection]'));
1001+
}
9711002
}

0 commit comments

Comments
 (0)