diff --git a/src/Symfony/Components/DomCrawler/Form.php b/src/Symfony/Components/DomCrawler/Form.php index a7f6e8705c..a8f370f1ff 100644 --- a/src/Symfony/Components/DomCrawler/Form.php +++ b/src/Symfony/Components/DomCrawler/Form.php @@ -69,41 +69,6 @@ class Form implements \ArrayAccess return $this->node; } - /** - * Gets the value of a field. - * - * @param string $name The field name - * - * @throws \InvalidArgumentException if the field does not exist - */ - public function getValue($name) - { - if (!$this->hasField($name)) { - throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name)); - } - - return $this->fields[$name]->getValue(); - } - - /** - * Sets the value of a field. - * - * @param string $name The field name - * @param string|array $value The value of the field - * - * @throws \InvalidArgumentException if the field does not exist - */ - public function setValue($name, $value) - { - if (!$this->hasField($name)) { - throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name)); - } - - $this->fields[$name]->setValue($value); - - return $this; - } - /** * Sets the value of the fields. * @@ -112,7 +77,7 @@ class Form implements \ArrayAccess public function setValues(array $values) { foreach ($values as $name => $value) { - $this->setValue($name, $value); + $this[$name] = $value; } return $this; @@ -337,7 +302,7 @@ class Form implements \ArrayAccess */ public function offsetExists($name) { - return $this->hasValue($name); + return $this->hasField($name); } /** @@ -349,7 +314,11 @@ class Form implements \ArrayAccess */ public function offsetGet($name) { - return $this->getValue($name); + if (!$this->hasField($name)) { + throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name)); + } + + return $this->fields[$name]->getValue(); } /** @@ -362,7 +331,11 @@ class Form implements \ArrayAccess */ public function offsetSet($name, $value) { - $this->setValue($name, $value); + if (!$this->hasField($name)) { + throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name)); + } + + $this->fields[$name]->setValue($value); } /** diff --git a/tests/Symfony/Tests/Components/DomCrawler/FormTest.php b/tests/Symfony/Tests/Components/DomCrawler/FormTest.php index 54df3d3432..d8ca5616e5 100644 --- a/tests/Symfony/Tests/Components/DomCrawler/FormTest.php +++ b/tests/Symfony/Tests/Components/DomCrawler/FormTest.php @@ -155,22 +155,21 @@ class FormTest extends \PHPUnit_Framework_TestCase { $form = $this->createForm('
'); - $this->assertEquals('foo', $form->getValue('foo'), '->getValue() returns the value of a form field'); + $this->assertEquals('foo', $form['foo'], '->getValue() returns the value of a form field'); - $ret = $form->setValue('foo', 'bar'); + $form['foo'] = 'bar'; - $this->assertEquals($form, $ret, '->setValue() implements a fluent interface'); - $this->assertEquals('bar', $form->getValue('foo'), '->setValue() changes the value of a form field'); + $this->assertEquals('bar', $form['foo'], '->setValue() changes the value of a form field'); try { - $form->setValue('foobar', 'bar'); + $form['foobar'] = 'bar'; $this->pass('->setValue() throws an \InvalidArgumentException exception if the field does not exist'); } catch (\InvalidArgumentException $e) { $this->assertTrue(true, '->setValue() throws an \InvalidArgumentException exception if the field does not exist'); } try { - $form->getValue('foobar'); + $form['foobar']; $this->pass('->getValue() throws an \InvalidArgumentException exception if the field does not exist'); } catch (\InvalidArgumentException $e) { $this->assertTrue(true, '->getValue() throws an \InvalidArgumentException exception if the field does not exist');