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 ...@@ -104,6 +104,17 @@ class Document implements \IteratorAggregate, \Countable, \ArrayAccess
return $this->document->__get($name); 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 * IteratorAggregate implementation
* *
......
...@@ -78,6 +78,20 @@ abstract class AbstractDocument implements \IteratorAggregate, \Countable, \Arra ...@@ -78,6 +78,20 @@ abstract class AbstractDocument implements \IteratorAggregate, \Countable, \Arra
return $this->fields[$name]; 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 * IteratorAggregate implementation
* *
......
...@@ -60,6 +60,28 @@ abstract class AbstractDocumentTest extends \PHPUnit_Framework_TestCase ...@@ -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() public function testSetField()
{ {
$this->setExpectedException('Solarium\Exception\RuntimeException'); $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