Skip to content

Commit 7191c9d

Browse files
committed
fixes #24: __toString() shouldn't be final and return the name (like in Java)
1 parent dcc17a8 commit 7191c9d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/MabeEnum/Enum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ final private function __construct($value, $ordinal = null)
5353
}
5454

5555
/**
56-
* Get the selected value
56+
* Get the current selected constant name
5757
* @return string
58-
* @see getValue()
58+
* @see getName()
5959
*/
60-
final public function __toString()
60+
public function __toString()
6161
{
62-
return (string) $this->value;
62+
return $this->getName();
6363
}
6464

6565
/**

tests/MabeEnumTest/EnumTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function testGetNameReturnsConstantNameOfCurrentValue()
2323
$this->assertSame('ONE', $enum->getName());
2424
}
2525

26-
public function testToStringMagicMethodReturnsValueAsString()
26+
public function testToStringMagicMethodReturnsName()
2727
{
2828
$enum = EnumWithoutDefaultValue::get(EnumWithoutDefaultValue::ONE);
29-
$this->assertSame('1', $enum->__toString());
29+
$this->assertSame('ONE', $enum->__toString());
3030
}
3131

3232
public function testEnumInheritance()

0 commit comments

Comments
 (0)