From 115dd3bdb327751b615015f2384b32ccb78f7328 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Mon, 16 Nov 2015 13:52:07 +0800 Subject: [PATCH 1/2] [EAV] Value::setAttribute add return this --- More/EAV/Tests/ValueTest.php | 3 +-- More/EAV/Value.php | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/More/EAV/Tests/ValueTest.php b/More/EAV/Tests/ValueTest.php index 1b96521..cecf600 100644 --- a/More/EAV/Tests/ValueTest.php +++ b/More/EAV/Tests/ValueTest.php @@ -40,7 +40,6 @@ class ValueTest extends \PHPUnit_Framework_TestCase $value->setName('Silver'); $this->assertSame($attribute, $value->getAttribute()); - $value->setAttribute($attribute); - $this->assertSame($attribute, $value->getAttribute()); + $this->assertSame($attribute, $value->setAttribute($attribute)->getAttribute()); } } diff --git a/More/EAV/Value.php b/More/EAV/Value.php index 617afdc..127f8ce 100644 --- a/More/EAV/Value.php +++ b/More/EAV/Value.php @@ -28,12 +28,15 @@ class Value implements ValueInterface /** * @param Attribute $attribute + * @return $this */ public function setAttribute(Attribute $attribute) { $this->attribute->removeValue($this); // Remove value from current attribute $attribute->addValue($this); // Add value to new attribute $this->attribute = $attribute; + + return $this; } /** From ba63419d83289698d9ca1158916d3ae097c015b2 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Mon, 16 Nov 2015 22:36:46 +0800 Subject: [PATCH 2/2] [EAV] keep unit test code consistency --- More/EAV/Tests/ValueTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/More/EAV/Tests/ValueTest.php b/More/EAV/Tests/ValueTest.php index cecf600..1b96521 100644 --- a/More/EAV/Tests/ValueTest.php +++ b/More/EAV/Tests/ValueTest.php @@ -40,6 +40,7 @@ class ValueTest extends \PHPUnit_Framework_TestCase $value->setName('Silver'); $this->assertSame($attribute, $value->getAttribute()); - $this->assertSame($attribute, $value->setAttribute($attribute)->getAttribute()); + $value->setAttribute($attribute); + $this->assertSame($attribute, $value->getAttribute()); } }