From ea35b657386819742210639229e1266ce0aae0ee Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 24 Mar 2017 14:35:34 +0300 Subject: [PATCH 1/5] check type of enumerations class --- src/Enum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } /** From b605b551f3968b0e7657cb253818e361a3a6236f Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 24 Mar 2017 15:00:34 +0300 Subject: [PATCH 2/5] Create EnumConflict --- tests/EnumConflict | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/EnumConflict diff --git a/tests/EnumConflict b/tests/EnumConflict new file mode 100644 index 0000000..a5fe180 --- /dev/null +++ b/tests/EnumConflict @@ -0,0 +1,23 @@ + + * @author Mirosław Filip + */ +class EnumConflict extends Enum +{ + const FOO = "foo"; + const BAR = "bar"; +} From 3c7344ed35a5a539c21c3a30da3b216728b7dd81 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 24 Mar 2017 15:02:32 +0300 Subject: [PATCH 3/5] test conflict values in equals() method --- tests/EnumTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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())); + } } From 04af0225f630a435d8e4b6e90476df59cb7429a3 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 24 Mar 2017 15:04:44 +0300 Subject: [PATCH 4/5] correct class name in annotations --- tests/EnumConflict | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/EnumConflict b/tests/EnumConflict index a5fe180..edeef37 100644 --- a/tests/EnumConflict +++ b/tests/EnumConflict @@ -10,8 +10,8 @@ use MyCLabs\Enum\Enum; /** * Class EnumConflict * - * @method static EnumFixture FOO() - * @method static EnumFixture BAR() + * @method static EnumConflict FOO() + * @method static EnumConflict BAR() * * @author Daniel Costa * @author Mirosław Filip From 7f61014ca6f6cf3d6fc27a497761687d17c2edc1 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 24 Mar 2017 15:11:29 +0300 Subject: [PATCH 5/5] Rename EnumConflict to EnumConflict.php --- tests/{EnumConflict => EnumConflict.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{EnumConflict => EnumConflict.php} (100%) diff --git a/tests/EnumConflict b/tests/EnumConflict.php similarity index 100% rename from tests/EnumConflict rename to tests/EnumConflict.php