Skip to content

Commit

Permalink
Fix VariantData::equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdifabio committed Oct 25, 2017
1 parent aca2003 commit aacdfd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/VariantData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public function getProductId(): string
return $this->productId;
}

public function equals($other): bool
{
return $other instanceof VariantData
&& parent::equals($other)
&& $this->productId === $other->productId;
}

public function toJson(): array
{
$json = parent::toJson();
Expand Down
12 changes: 12 additions & 0 deletions test/unit/VariantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public function testVariantIdSameAsProductIdThrows()
{
VariantData::of('foo', 'foo');
}

public function testEquals()
{
$product1 = VariantData::of('foo', 'bar')
->withAttributeValue(AttributeValue::of('colour', 'red'));
$product2 = VariantData::of('foo', 'bar')
->withAttributeValue(AttributeValue::of('colour', 'red'));
self::assertTrue($product1->equals($product2));
$product3 = VariantData::of('foo', 'baz')
->withAttributeValue(AttributeValue::of('colour', 'red'));
self::assertFalse($product1->equals($product3));
}
}

0 comments on commit aacdfd1

Please sign in to comment.