public static function toBoolean($string)
{
if (is_numeric($string)) {
return $string != 0;
}
return filter_var($string, FILTER_VALIDATE_BOOLEAN);
}
/** * @test * @dataProvider toBoolean * @param $string * @param $expected */ public function shouldConvertToBoolean($string, $expected) { //when $toBoolean = Booleans::toBoolean($string); //then $this->assertEquals($expected, $toBoolean, 'To convert: ' . Objects::toString($string) . ' Expected: ' . Objects::toString($expected)); }