BooleanType
This commit is contained in:
parent
0fa64aecd7
commit
62a21e4455
49
src/Contracts/Types/Boolean.php
Normal file
49
src/Contracts/Types/Boolean.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Contracts\Types;
|
||||||
|
|
||||||
|
use Web3\Contracts\SolidityType;
|
||||||
|
use Web3\Contracts\Types\IType;
|
||||||
|
|
||||||
|
class Boolean extends SolidityType implements IType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isType
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isType($name)
|
||||||
|
{
|
||||||
|
return (preg_match('/bool(\[([0-9]+)\])?/', $name) === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isDynamicType
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDynamicType()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
69
test/unit/BoolTypeTest.php
Normal file
69
test/unit/BoolTypeTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Test\TestCase;
|
||||||
|
use Web3\Contracts\Types\Boolean;
|
||||||
|
|
||||||
|
class BoolTypeTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* testTypes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $testTypes = [
|
||||||
|
[
|
||||||
|
'value' => 'bool',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'bool[]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'bool[4]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'bool[][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'bool[3][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'bool[][6][]',
|
||||||
|
'result' => true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* solidityType
|
||||||
|
*
|
||||||
|
* @var \Web3\Contracts\SolidityType
|
||||||
|
*/
|
||||||
|
protected $solidityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->solidityType = new Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testIsType
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIsType()
|
||||||
|
{
|
||||||
|
$solidityType = $this->solidityType;
|
||||||
|
|
||||||
|
foreach ($this->testTypes as $type) {
|
||||||
|
$this->assertEquals($solidityType->isType($type['value']), $type['result']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user