Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  [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
  [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
  • Loading branch information
fabpot committed Feb 29, 2020
2 parents 1e6314d + 11dcf08 commit 4368bdd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function remove(string $name)
/**
* Gets a named field.
*
* @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 @@ -317,7 +317,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 FormFieldRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function remove(string $name)
/**
* Returns the value of the field based on the fully qualifed name and its children.
*
* @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 Tests/FormTest.php
Original file line number Diff line number Diff line change
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 @@ -965,7 +966,7 @@ protected function createTestMultipleForm()
return $dom;
}

public function testgetPhpValuesWithEmptyTextarea()
public function testGetPhpValuesWithEmptyTextarea()
{
$dom = new \DOMDocument();
$dom->loadHTML('
Expand All @@ -980,4 +981,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 4368bdd

Please sign in to comment.