Skip to content

Commit e5976f1

Browse files
committed
Merge pull request #14 from mirfilip/hotfix/search-type-safe
Fix for search() is not type safe. Fixes #13
2 parents 82d35ba + ac0424e commit e5976f1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Diff for: src/Enum.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function isValidKey($key)
131131
*/
132132
public static function search($value)
133133
{
134-
return array_search($value, self::toArray());
134+
return array_search($value, self::toArray(), true);
135135
}
136136

137137
/**

Diff for: tests/EnumTest.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,23 @@ public function testIsValidKey()
175175

176176
/**
177177
* search()
178+
* @see https://github.com/myclabs/php-enum/issues/13
179+
* @dataProvider searchProvider
178180
*/
179-
public function testSearch()
181+
public function testSearch($value, $expected)
180182
{
181-
$this->assertEquals('FOO', EnumFixture::search('foo'));
182-
/**
183-
* @see https://github.com/myclabs/php-enum/issues/9
184-
*/
185-
$this->assertEquals(EnumFixture::PROBLEMATIC_NUMBER, EnumFixture::search(1));
183+
$this->assertSame($expected, EnumFixture::search($value));
184+
}
185+
186+
public function searchProvider() {
187+
return array(
188+
array('foo', 'FOO'),
189+
array(0, 'PROBLEMATIC_NUMBER'),
190+
array(null, 'PROBLEMATIC_NULL'),
191+
array('', 'PROBLEMATIC_EMPTY_STRING'),
192+
array(false, 'PROBLEMATIC_BOOLEAN_FALSE'),
193+
array('bar I do not exist', false),
194+
array(array(), false),
195+
);
186196
}
187197
}

0 commit comments

Comments
 (0)