[DomCrawler] removed redundant methods
This commit is contained in:
parent
a26bdb7723
commit
2722da2146
@ -69,41 +69,6 @@ class Form implements \ArrayAccess
|
|||||||
return $this->node;
|
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.
|
* Sets the value of the fields.
|
||||||
*
|
*
|
||||||
@ -112,7 +77,7 @@ class Form implements \ArrayAccess
|
|||||||
public function setValues(array $values)
|
public function setValues(array $values)
|
||||||
{
|
{
|
||||||
foreach ($values as $name => $value) {
|
foreach ($values as $name => $value) {
|
||||||
$this->setValue($name, $value);
|
$this[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -337,7 +302,7 @@ class Form implements \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function offsetExists($name)
|
public function offsetExists($name)
|
||||||
{
|
{
|
||||||
return $this->hasValue($name);
|
return $this->hasField($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -349,7 +314,11 @@ class Form implements \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function offsetGet($name)
|
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)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,22 +155,21 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
||||||
|
|
||||||
$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['foo'], '->setValue() changes the value of a form field');
|
||||||
$this->assertEquals('bar', $form->getValue('foo'), '->setValue() changes the value of a form field');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$form->setValue('foobar', 'bar');
|
$form['foobar'] = 'bar';
|
||||||
$this->pass('->setValue() throws an \InvalidArgumentException exception if the field does not exist');
|
$this->pass('->setValue() throws an \InvalidArgumentException exception if the field does not exist');
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
$this->assertTrue(true, '->setValue() throws an \InvalidArgumentException exception if the field does not exist');
|
$this->assertTrue(true, '->setValue() throws an \InvalidArgumentException exception if the field does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$form->getValue('foobar');
|
$form['foobar'];
|
||||||
$this->pass('->getValue() throws an \InvalidArgumentException exception if the field does not exist');
|
$this->pass('->getValue() throws an \InvalidArgumentException exception if the field does not exist');
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
$this->assertTrue(true, '->getValue() throws an \InvalidArgumentException exception if the field does not exist');
|
$this->assertTrue(true, '->getValue() throws an \InvalidArgumentException exception if the field does not exist');
|
||||||
|
Reference in New Issue
Block a user