From ac0424eb204e71febd4d3bba694b60e98b064704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miros=C5=82aw=20Filip?= Date: Mon, 9 Feb 2015 10:05:55 +0100 Subject: [PATCH] Fix for search() is not type safe. Fixes #13 --- src/Enum.php | 2 +- tests/EnumTest.php | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) 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), + ); } }