diff --git a/src/Attribute/AttributeAware.php b/src/Attribute/AttributeAware.php index 8c4bd283..168810b5 100644 --- a/src/Attribute/AttributeAware.php +++ b/src/Attribute/AttributeAware.php @@ -26,6 +26,13 @@ public function getAttribute($name, $default = null); */ public function setAttribute($name, $value); + /** + * Removes a single attribute with the given $name + * + * @param string $name + */ + public function removeAttribute($name); + /** * get a container for all attributes * diff --git a/src/Attribute/AttributeBag.php b/src/Attribute/AttributeBag.php index f6841cbf..ff465ec8 100644 --- a/src/Attribute/AttributeBag.php +++ b/src/Attribute/AttributeBag.php @@ -9,6 +9,7 @@ interface AttributeBag extends AttributeAware { // public function getAttribute($name, $default); // public function setAttribute($name, $value); + // public function removeAttribute(); // public function getAttributeBag(); /** diff --git a/src/Attribute/AttributeBagContainer.php b/src/Attribute/AttributeBagContainer.php index 451eee8c..77286f72 100644 --- a/src/Attribute/AttributeBagContainer.php +++ b/src/Attribute/AttributeBagContainer.php @@ -41,6 +41,16 @@ public function setAttribute($name, $value) return $this; } + /** + * Removes a single attribute with the given $name + * + * @param string $name + */ + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + /** * get an array of all attributes * diff --git a/src/Attribute/AttributeBagNamespaced.php b/src/Attribute/AttributeBagNamespaced.php index 2e234123..98bab3b1 100644 --- a/src/Attribute/AttributeBagNamespaced.php +++ b/src/Attribute/AttributeBagNamespaced.php @@ -68,6 +68,16 @@ public function setAttribute($name, $value) $this->bag->setAttribute($this->prefix . $name, $value); } + /** + * Removes a single attribute with the given $name + * + * @param string $name + */ + public function removeAttribute($name) + { + $this->bag->removeAttribute($this->prefix . $name); + } + /** * get an array of all attributes * diff --git a/src/Attribute/AttributeBagReference.php b/src/Attribute/AttributeBagReference.php index 2aae6376..f7ff0e8f 100644 --- a/src/Attribute/AttributeBagReference.php +++ b/src/Attribute/AttributeBagReference.php @@ -55,6 +55,16 @@ public function setAttribute($name, $value) return $this; } + /** + * Removes a single attribute with the given $name + * + * @param string $name + */ + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + /** * get an array of all attributes * diff --git a/src/Edge/Base.php b/src/Edge/Base.php index c4ef7c8e..d019c4e2 100644 --- a/src/Edge/Base.php +++ b/src/Edge/Base.php @@ -303,6 +303,11 @@ public function setAttribute($name, $value) $this->attributes[$name] = $value; } + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + public function getAttributeBag() { return new AttributeBagReference($this->attributes); diff --git a/src/Graph.php b/src/Graph.php index 3728b4e3..f5a0f98a 100644 --- a/src/Graph.php +++ b/src/Graph.php @@ -462,6 +462,11 @@ public function setAttribute($name, $value) $this->attributes[$name] = $value; } + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + public function getAttributeBag() { return new AttributeBagReference($this->attributes); diff --git a/src/Vertex.php b/src/Vertex.php index a020de40..af6bbe79 100644 --- a/src/Vertex.php +++ b/src/Vertex.php @@ -382,6 +382,11 @@ public function setAttribute($name, $value) $this->attributes[$name] = $value; } + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + public function getAttributeBag() { return new AttributeBagReference($this->attributes); diff --git a/tests/Attribute/AbstractAttributeAwareTest.php b/tests/Attribute/AbstractAttributeAwareTest.php index 869ca0fe..2a2e4dc7 100644 --- a/tests/Attribute/AbstractAttributeAwareTest.php +++ b/tests/Attribute/AbstractAttributeAwareTest.php @@ -27,6 +27,19 @@ public function testAttributeSetGetDefault(AttributeAware $entity) $this->assertEquals('default', $entity->getAttribute('unknown', 'default')); } + /** + * @depends testAttributeAwareInterface + * @param AttributeAware $entity + */ + public function testAttributeSetRemoveGet(AttributeAware $entity) + { + $entity->setAttribute('test', 'value'); + $this->assertEquals('value', $entity->getAttribute('test')); + + $entity->removeAttribute('test'); + $this->assertEquals(null, $entity->getAttribute('test')); + } + /** * @depends testAttributeAwareInterface * @param AttributeAware $entity diff --git a/tests/Attribute/AttributeBagContainerTest.php b/tests/Attribute/AttributeBagContainerTest.php index 66807726..c8382faa 100644 --- a/tests/Attribute/AttributeBagContainerTest.php +++ b/tests/Attribute/AttributeBagContainerTest.php @@ -2,8 +2,13 @@ use Fhaculty\Graph\Attribute\AttributeBagContainer; -class AttributeBagContainerTest extends TestCase +class AttributeBagContainerTest extends AbstractAttributeAwareTest { + protected function createAttributeAware() + { + return new AttributeBagContainer(); + } + public function testEmpty() { $bag = new AttributeBagContainer(); diff --git a/tests/Attribute/AttributeBagNamespacedTest.php b/tests/Attribute/AttributeBagNamespacedTest.php index 0ac11c64..ffffa6ee 100644 --- a/tests/Attribute/AttributeBagNamespacedTest.php +++ b/tests/Attribute/AttributeBagNamespacedTest.php @@ -5,8 +5,13 @@ use Fhaculty\Graph\Attribute\AttributeAware; use Fhaculty\Graph\Attribute\AttributeBagContainer; -class AtributeBagNamespacedTest extends TestCase +class AtributeBagNamespacedTest extends AbstractAttributeAwareTest { + protected function createAttributeAware() + { + return new AttributeBagNamespaced(new AttributeBagContainer(), 'test.'); + } + public function testBagContainer() { $container = new AttributeBagContainer(); diff --git a/tests/Attribute/AttributeBagReferenceTest.php b/tests/Attribute/AttributeBagReferenceTest.php index d03248a1..54e5f95c 100644 --- a/tests/Attribute/AttributeBagReferenceTest.php +++ b/tests/Attribute/AttributeBagReferenceTest.php @@ -2,8 +2,15 @@ use Fhaculty\Graph\Attribute\AttributeBagReference; -class AttributeBagReferenceTest extends TestCase +class AttributeBagReferenceTest extends AbstractAttributeAwareTest { + protected function createAttributeAware() + { + $attributes = array(); + + return new AttributeBagReference($attributes); + } + public function testEmpty() { $attributes = array();