Commit baa133ec authored by Robin Kunde's avatar Robin Kunde

added support for calling empty() and isset() on result document properties

parent 6af1b2da
......@@ -104,6 +104,17 @@ class Document implements \IteratorAggregate, \Countable, \ArrayAccess
return $this->document->__get($name);
}
/**
* Forward isset call to the original document
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
return $this->document->__isset($name);
}
/**
* IteratorAggregate implementation
*
......
......@@ -78,6 +78,20 @@ abstract class AbstractDocument implements \IteratorAggregate, \Countable, \Arra
return $this->fields[$name];
}
/**
* Check if field is set by name
*
* Magic method for checking if fields are set as properties of this document
* object, by field name. Also used by empty().
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
return isset($this->fields[$name]);
}
/**
* IteratorAggregate implementation
*
......
......@@ -60,6 +60,28 @@ abstract class AbstractDocumentTest extends \PHPUnit_Framework_TestCase
);
}
public function testPropertyIsset()
{
$this->assertTrue(
isset($this->doc->categories)
);
$this->assertFalse(
isset($this->doc->invalidfieldname)
);
}
public function testPropertyEmpty()
{
$this->assertTrue(
empty($this->doc->empty_field)
);
$this->assertFalse(
empty($this->doc->categories)
);
}
public function testSetField()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
......
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