Skip to content

Commit

Permalink
[DomCrawler][Form] Fix PHPDoc on get & offsetGet
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyweb committed Feb 26, 2020
1 parent 159ef1b commit f8735cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -269,7 +269,7 @@ public function remove($name)
*
* @param string $name The field name
*
* @return FormField The field instance
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException When field is not present in this form
*/
Expand Down Expand Up @@ -313,7 +313,7 @@ public function offsetExists($name)
*
* @param string $name The field name
*
* @return FormField The associated Field instance
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException if the field does not exist
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/FormFieldRegistry.php
Expand Up @@ -70,7 +70,7 @@ public function remove($name)
*
* @param string $name The fully qualified name of the field
*
* @return mixed The value of the field
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException if the field does not exist
*/
Expand Down
33 changes: 32 additions & 1 deletion src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DomCrawler\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Field\TextareaFormField;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\DomCrawler\FormFieldRegistry;

Expand Down Expand Up @@ -953,7 +954,7 @@ protected function createTestMultipleForm()
return $dom;
}

public function testgetPhpValuesWithEmptyTextarea()
public function testGetPhpValuesWithEmptyTextarea()
{
$dom = new \DOMDocument();
$dom->loadHTML('
Expand All @@ -968,4 +969,34 @@ public function testgetPhpValuesWithEmptyTextarea()
$form = new Form($nodes->item(0), 'http://example.com');
$this->assertEquals($form->getPhpValues(), ['example' => '']);
}

public function testGetReturnTypes()
{
$dom = new \DOMDocument();
$dom->loadHTML('
<html>
<form>
<textarea name="foo[collection][0][bar]">item 0</textarea>
</form>
</html>'
);

$nodes = $dom->getElementsByTagName('form');
$form = new Form($nodes->item(0), 'http://example.com');

// FormField
$this->assertInstanceOf(TextareaFormField::class, $textareaFormField = $form->get('foo[collection][0][bar]'));

// Array of FormField
$this->assertSame([
'bar' => $textareaFormField,
], $form->get('foo[collection][0]'));

// Array of array of FormField
$this->assertSame([
[
'bar' => $textareaFormField,
],
], $form->get('foo[collection]'));
}
}

0 comments on commit f8735cc

Please sign in to comment.