Skip to content

Adds Enum::equals() #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2016
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()));
}
}