Skip to content

Commit

Permalink
Merge pull request #48 from peter-gribanov/equals-fix
Browse files Browse the repository at this point in the history
Fix method equals is incorrect working
  • Loading branch information
mnapoli authored Mar 26, 2017
2 parents 3eec06c + 7f61014 commit 61f4a24
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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 <danielcosta@gmail.com>
* @author Mirosław Filip <mirfilip@gmail.com>
*/
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()));
}
}

0 comments on commit 61f4a24

Please sign in to comment.