Skip to content

Commit

Permalink
Merge pull request graphp#138 from clue-labs/remove-attribute
Browse files Browse the repository at this point in the history
Added AttributeAware::removeAttribute()
  • Loading branch information
clue committed Oct 2, 2015
2 parents 0336a4d + 4c0a334 commit 9159d94
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Attribute/AttributeAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions src/Attribute/AttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface AttributeBag extends AttributeAware
{
// public function getAttribute($name, $default);
// public function setAttribute($name, $value);
// public function removeAttribute();
// public function getAttributeBag();

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagNamespaced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions src/Edge/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/Vertex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions tests/Attribute/AbstractAttributeAwareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/Attribute/AttributeBagContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion tests/Attribute/AttributeBagNamespacedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion tests/Attribute/AttributeBagReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9159d94

Please sign in to comment.