Skip to content

Commit

Permalink
fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
henzeb committed Jun 8, 2022
1 parent a120e54 commit 3b85c65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Helpers/EnumSubsetMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/EnhancedBackedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Concerns/ComparisonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public function testWhenStringEqualsValue()
);
}

public function testWhenStringEqualsValueWithCapitals()
{
$this->assertTrue(
EnhancedBackedEnum::WITH_CAPITALS->equals('THIRD enum')
);
}

public function testWhenStringNotEqualsValue()
{
$this->assertFalse(
Expand Down

0 comments on commit 3b85c65

Please sign in to comment.