diff --git a/src/Enum.php b/src/Enum.php index d2fb864..ce0dd80 100755 --- a/src/Enum.php +++ b/src/Enum.php @@ -131,7 +131,7 @@ public static function isValidKey($key) */ public static function search($value) { - return array_search($value, self::toArray()); + return array_search($value, self::toArray(), true); } /** diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 64270bb..88b2c5f 100755 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -175,13 +175,23 @@ public function testIsValidKey() /** * search() + * @see https://github.com/myclabs/php-enum/issues/13 + * @dataProvider searchProvider */ - public function testSearch() + public function testSearch($value, $expected) { - $this->assertEquals('FOO', EnumFixture::search('foo')); - /** - * @see https://github.com/myclabs/php-enum/issues/9 - */ - $this->assertEquals(EnumFixture::PROBLEMATIC_NUMBER, EnumFixture::search(1)); + $this->assertSame($expected, EnumFixture::search($value)); + } + + public function searchProvider() { + return array( + array('foo', 'FOO'), + array(0, 'PROBLEMATIC_NUMBER'), + array(null, 'PROBLEMATIC_NULL'), + array('', 'PROBLEMATIC_EMPTY_STRING'), + array(false, 'PROBLEMATIC_BOOLEAN_FALSE'), + array('bar I do not exist', false), + array(array(), false), + ); } }