1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-13 08:44:01 +02:00

Added toBoolean

This commit is contained in:
Daniel St. Jules
2015-07-23 23:40:21 -07:00
parent 6b74918cc9
commit bded15d683
3 changed files with 82 additions and 0 deletions

View File

@@ -820,6 +820,39 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
);
}
/**
* @dataProvider toBooleanProvider()
*/
public function testToBoolean($expected, $str, $encoding = null)
{
$stringy = S::create($str, $encoding);
$result = $stringy->toBoolean();
$this->assertInternalType('boolean', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($str, $stringy);
}
public function toBooleanProvider()
{
return array(
array(true, 'true'),
array(true, '1'),
array(true, 'on'),
array(true, 'ON'),
array(true, 'yes'),
array(true, '999'),
array(false, 'false'),
array(false, '0'),
array(false, 'off'),
array(false, 'OFF'),
array(false, 'no'),
array(false, '-999'),
array(false, ''),
array(false, ' '),
array(false, '', 'UTF-8') // narrow no-break space (U+202F)
);
}
/**
* @dataProvider toSpacesProvider()
*/