Skip to content

Fix method equals is incorrect working #48

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 5 commits into from
Mar 26, 2017
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
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/EnumConflict.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @link http://github.com/myclabs/php-enum
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
*/
namespace MyCLabs\Tests\Enum;

use MyCLabs\Enum\Enum;

/**
* Class EnumConflict
*
* @method static EnumConflict FOO()
* @method static EnumConflict BAR()
*
* @author Daniel Costa <[email protected]>
* @author Mirosław Filip <[email protected]>
*/
class EnumConflict extends Enum
{
const FOO = "foo";
const BAR = "bar";
}
8 changes: 8 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}