Fix BooleanFormatter.

This commit is contained in:
sc0Vu 2018-02-21 09:52:22 +08:00
parent b9cf0edc27
commit b755295a71
3 changed files with 10 additions and 10 deletions

View File

@ -4,4 +4,4 @@ require('../vendor/autoload.php');
use Web3\Web3;
$web3 = new Web3('http://192.168.99.100:8545');
$web3 = new Web3('http://192.168.99.100:8545/');

View File

@ -21,13 +21,10 @@ class BooleanFormatter implements IFormatter
* format
*
* @param mixed $value
* @return int
* @return bool
*/
public static function format($value)
{
if (!is_bool($value)) {
throw new InvalidArgumentException('The value to inputFormat function must be boolean.');
}
return (int) $value;
return (bool) $value;
}
}

View File

@ -36,12 +36,15 @@ class BooleanFormatterTest extends TestCase
$formatter = $this->formatter;
$boolean = $formatter->format(true);
$this->assertEquals($boolean, 1);
$this->assertEquals($boolean, true);
$boolean = $formatter->format(1);
$this->assertEquals($boolean, true);
$boolean = $formatter->format(false);
$this->assertEquals($boolean, 0);
$this->assertEquals($boolean, false);
$this->expectException(InvalidArgumentException::class);
$boolean = $formatter->format('boolean');
$boolean = $formatter->format(0);
$this->assertEquals($boolean, false);
}
}