Pārlūkot izejas kodu

[DomCrawler] fixed API

Fabien Potencier 15 gadi atpakaļ
vecāks
revīzija
bd9f11f8f6

+ 3 - 1
src/Symfony/Components/DomCrawler/Form.php

@@ -310,6 +310,8 @@ class Form implements \ArrayAccess
      *
      * @param string $name The field name
      *
+     * @return Symfony\Components\DomCrawler\Field The associated Field instance
+     *
      * @throws \InvalidArgumentException if the field does not exist
      */
     public function offsetGet($name)
@@ -318,7 +320,7 @@ class Form implements \ArrayAccess
             throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name));
         }
 
-        return $this->fields[$name]->getValue();
+        return $this->fields[$name];
     }
 
     /**

+ 6 - 6
tests/Symfony/Tests/Components/DomCrawler/FormTest.php

@@ -155,24 +155,24 @@ class FormTest extends \PHPUnit_Framework_TestCase
     {
         $form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
 
-        $this->assertEquals('foo', $form['foo'], '->getValue() returns the value of a form field');
+        $this->assertEquals('foo', $form['foo']->getValue(), '->__offsetGet() returns the value of a form field');
 
         $form['foo'] = 'bar';
 
-        $this->assertEquals('bar', $form['foo'], '->setValue() changes the value of a form field');
+        $this->assertEquals('bar', $form['foo']->getValue(), '->__offsetSet() changes the value of a form field');
 
         try {
             $form['foobar'] = 'bar';
-            $this->pass('->setValue() throws an \InvalidArgumentException exception if the field does not exist');
+            $this->pass('->__offsetSet() 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');
+            $this->assertTrue(true, '->__offsetSet() throws an \InvalidArgumentException exception if the field does not exist');
         }
 
         try {
             $form['foobar'];
-            $this->pass('->getValue() throws an \InvalidArgumentException exception if the field does not exist');
+            $this->pass('->__offsetSet() 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');
+            $this->assertTrue(true, '->__offsetSet() throws an \InvalidArgumentException exception if the field does not exist');
         }
     }