Skip to content

Commit

Permalink
minor #35861 [DomCrawler][Form] Fix PHPDoc on get & offsetGet (fancyweb)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[DomCrawler][Form] Fix PHPDoc on get & offsetGet

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

`FormFieldRegistry::get()` returns mixed. For example, it can return an array when the field is a collection.

Commits
-------

f8735cc [DomCrawler][Form] Fix PHPDoc on get & offsetGet
  • Loading branch information
nicolas-grekas committed Feb 27, 2020
2 parents dd8f580 + f8735cc commit 5ffb964
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 5ffb964

Please sign in to comment.