diff --git a/src/Enum.php b/src/Enum.php index 517fbc9..140e722 100755 --- a/src/Enum.php +++ b/src/Enum.php @@ -82,7 +82,7 @@ public function __toString() */ final public function equals(Enum $enum) { - return $this->getValue() === $enum->getValue(); + return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum); } /** diff --git a/tests/EnumConflict.php b/tests/EnumConflict.php new file mode 100644 index 0000000..edeef37 --- /dev/null +++ b/tests/EnumConflict.php @@ -0,0 +1,23 @@ + + * @author Mirosław Filip + */ +class EnumConflict extends Enum +{ + const FOO = "foo"; + const BAR = "bar"; +} diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 14079ed..72ec873 100755 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -242,4 +242,12 @@ public function testEqualsComparesProblematicValuesProperly() $this->assertFalse($emptyString->equals($null)); $this->assertFalse($null->equals($false)); } + + /** + * equals() + */ + public function testEqualsConflictValues() + { + $this->assertFalse(EnumFixture::FOO()->equals(EnumConflict::FOO())); + } }