diff --git a/src/VariantData.php b/src/VariantData.php index 6100ad7..89f8b60 100644 --- a/src/VariantData.php +++ b/src/VariantData.php @@ -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(); diff --git a/test/unit/VariantTest.php b/test/unit/VariantTest.php index 4483e7b..fb43262 100644 --- a/test/unit/VariantTest.php +++ b/test/unit/VariantTest.php @@ -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)); + } }