Fix BooleanFormatter.
This commit is contained in:
parent
b9cf0edc27
commit
b755295a71
@ -4,4 +4,4 @@ require('../vendor/autoload.php');
|
|||||||
|
|
||||||
use Web3\Web3;
|
use Web3\Web3;
|
||||||
|
|
||||||
$web3 = new Web3('http://192.168.99.100:8545');
|
$web3 = new Web3('http://192.168.99.100:8545/');
|
@ -21,13 +21,10 @@ class BooleanFormatter implements IFormatter
|
|||||||
* format
|
* format
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return int
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function format($value)
|
public static function format($value)
|
||||||
{
|
{
|
||||||
if (!is_bool($value)) {
|
return (bool) $value;
|
||||||
throw new InvalidArgumentException('The value to inputFormat function must be boolean.');
|
|
||||||
}
|
|
||||||
return (int) $value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,12 +36,15 @@ class BooleanFormatterTest extends TestCase
|
|||||||
$formatter = $this->formatter;
|
$formatter = $this->formatter;
|
||||||
|
|
||||||
$boolean = $formatter->format(true);
|
$boolean = $formatter->format(true);
|
||||||
$this->assertEquals($boolean, 1);
|
$this->assertEquals($boolean, true);
|
||||||
|
|
||||||
|
$boolean = $formatter->format(1);
|
||||||
|
$this->assertEquals($boolean, true);
|
||||||
|
|
||||||
$boolean = $formatter->format(false);
|
$boolean = $formatter->format(false);
|
||||||
$this->assertEquals($boolean, 0);
|
$this->assertEquals($boolean, false);
|
||||||
|
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$boolean = $formatter->format(0);
|
||||||
$boolean = $formatter->format('boolean');
|
$this->assertEquals($boolean, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user