Skip to content

Commit 61f4a24

Browse files
authored
Merge pull request #48 from peter-gribanov/equals-fix
Fix method equals is incorrect working
2 parents 3eec06c + 7f61014 commit 61f4a24

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Enum.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __toString()
8282
*/
8383
final public function equals(Enum $enum)
8484
{
85-
return $this->getValue() === $enum->getValue();
85+
return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
8686
}
8787

8888
/**

tests/EnumConflict.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @link http://github.com/myclabs/php-enum
4+
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
5+
*/
6+
namespace MyCLabs\Tests\Enum;
7+
8+
use MyCLabs\Enum\Enum;
9+
10+
/**
11+
* Class EnumConflict
12+
*
13+
* @method static EnumConflict FOO()
14+
* @method static EnumConflict BAR()
15+
*
16+
* @author Daniel Costa <[email protected]>
17+
* @author Mirosław Filip <[email protected]>
18+
*/
19+
class EnumConflict extends Enum
20+
{
21+
const FOO = "foo";
22+
const BAR = "bar";
23+
}

tests/EnumTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,12 @@ public function testEqualsComparesProblematicValuesProperly()
242242
$this->assertFalse($emptyString->equals($null));
243243
$this->assertFalse($null->equals($false));
244244
}
245+
246+
/**
247+
* equals()
248+
*/
249+
public function testEqualsConflictValues()
250+
{
251+
$this->assertFalse(EnumFixture::FOO()->equals(EnumConflict::FOO()));
252+
}
245253
}

0 commit comments

Comments
 (0)