Commit bb26c423 authored by Bas de Nooijer's avatar Bas de Nooijer

- added array implementation to ReadWrite document

- updated ReadWrite document unittest
parent 9959cad4
......@@ -86,8 +86,7 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter_Http
);
// forward adapter options if available
if( isset($this->_options['adapteroptions']))
{
if (isset($this->_options['adapteroptions'])) {
$this->_zendHttp->setConfig($this->_options['adapteroptions']);
}
}
......
......@@ -202,13 +202,19 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
* Magic method for setting fields as properties of this document
* object, by field name.
*
* If you supply NULL as the value the field will be removed
*
* @param string $name
* @param string $value
* @param string|null $value
* @return void
*/
public function __set($name, $value)
{
$this->setField($name, $value);
if ($value == null) {
$this->removeField($name);
} else {
$this->setField($name, $value);
}
}
}
\ No newline at end of file
......@@ -141,6 +141,19 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase
);
}
public function testRemoveFieldBySettingToNull()
{
$this->_doc->setField('name', NULL);
$expectedFields = $this->_fields;
unset($expectedFields['name']);
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testRemoveFieldBoostRemoval()
{
$this->_doc->setFieldBoost('name',3.2);
......@@ -198,5 +211,31 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase
$this->_doc->name
);
}
public function testSetFieldAsArray()
{
$this->_doc['name'] = 'newname';
$expectedFields = $this->_fields;
$expectedFields['name'] = 'newname';
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testRemoveFieldAsArray()
{
unset($this->_doc['name']);
$expectedFields = $this->_fields;
unset($expectedFields['name']);
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment