diff --git a/src/Helpers/EnumSubsetMethods.php b/src/Helpers/EnumSubsetMethods.php index 608adad..e974328 100644 --- a/src/Helpers/EnumSubsetMethods.php +++ b/src/Helpers/EnumSubsetMethods.php @@ -41,21 +41,22 @@ public function equals(UnitEnum|string|int ...$equals): bool private function compare(UnitEnum $enum, UnitEnum|string|int ...$equals): bool { - foreach ($equals as $equal) { + $value = EnumValue::value($enum); - if(is_string($equal)) { - $equal = strtolower($equal); + foreach ($equals as $equal) { + if($enum === $equal) { + return true; } if(is_object($equal)) { $equal = EnumValue::value($equal); } - if (strtolower($enum->name) === $equal) { + if(strtolower($enum->name) === strtolower($equal)) { return true; } - if((string)EnumValue::value($enum) === (string)$equal) { + if(strtolower($value) === strtolower($equal)) { return true; } } diff --git a/tests/Fixtures/EnhancedBackedEnum.php b/tests/Fixtures/EnhancedBackedEnum.php index a26983c..0107054 100644 --- a/tests/Fixtures/EnhancedBackedEnum.php +++ b/tests/Fixtures/EnhancedBackedEnum.php @@ -20,6 +20,7 @@ enum EnhancedBackedEnum: string case ENUM = 'an enum'; case ANOTHER_ENUM = 'another enum'; case ENUM_3 = 'third_enum'; + case WITH_CAPITALS = 'THIRD enum'; protected function labels(): array { diff --git a/tests/Unit/Concerns/ComparisonTest.php b/tests/Unit/Concerns/ComparisonTest.php index 2213174..499c251 100644 --- a/tests/Unit/Concerns/ComparisonTest.php +++ b/tests/Unit/Concerns/ComparisonTest.php @@ -73,6 +73,13 @@ public function testWhenStringEqualsValue() ); } + public function testWhenStringEqualsValueWithCapitals() + { + $this->assertTrue( + EnhancedBackedEnum::WITH_CAPITALS->equals('THIRD enum') + ); + } + public function testWhenStringNotEqualsValue() { $this->assertFalse(