Skip to content

Commit

Permalink
Merge pull request #14 from mirfilip/hotfix/search-type-safe
Browse files Browse the repository at this point in the history
Fix for search() is not type safe. Fixes #13
  • Loading branch information
mnapoli committed Feb 15, 2015
2 parents 82d35ba + ac0424e commit e5976f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
22 changes: 16 additions & 6 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
}

0 comments on commit e5976f1

Please sign in to comment.