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 ...@@ -86,8 +86,7 @@ class Solarium_Client_Adapter_ZendHttp extends Solarium_Client_Adapter_Http
); );
// forward adapter options if available // forward adapter options if available
if( isset($this->_options['adapteroptions'])) if (isset($this->_options['adapteroptions'])) {
{
$this->_zendHttp->setConfig($this->_options['adapteroptions']); $this->_zendHttp->setConfig($this->_options['adapteroptions']);
} }
} }
......
...@@ -202,13 +202,19 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly ...@@ -202,13 +202,19 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
* Magic method for setting fields as properties of this document * Magic method for setting fields as properties of this document
* object, by field name. * object, by field name.
* *
* If you supply NULL as the value the field will be removed
*
* @param string $name * @param string $name
* @param string $value * @param string|null $value
* @return void * @return void
*/ */
public function __set($name, $value) public function __set($name, $value)
{ {
if ($value == null) {
$this->removeField($name);
} else {
$this->setField($name, $value); $this->setField($name, $value);
} }
}
} }
\ No newline at end of file
...@@ -141,6 +141,19 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase ...@@ -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() public function testRemoveFieldBoostRemoval()
{ {
$this->_doc->setFieldBoost('name',3.2); $this->_doc->setFieldBoost('name',3.2);
...@@ -199,4 +212,30 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase ...@@ -199,4 +212,30 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase
); );
} }
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