Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public function __toString()
return (string)$this->value;
}

/**
* Compares one Enum with another.
*
* @return bool True if Enums are equal, false if not equal
*/
public function equals(Enum $enum)
{
return $this->getValue() === $enum->getValue();
}

/**
* Returns the names (keys) of all constants in the Enum class
*
Expand Down
9 changes: 9 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,13 @@ public function searchProvider() {
array(array(), false),
);
}

public function testEquals()
{
$enum = new EnumFixture(EnumFixture::FOO);
$this->assertTrue($enum->equals(EnumFixture::FOO()));

$enum = new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE);
$this->assertFalse($enum->equals(EnumFixture::PROBLEMATIC_EMPTY_STRING()));
}
}