StrType
This commit is contained in:
parent
12470f3b90
commit
152d956b3d
49
src/Contracts/Types/Str.php
Normal file
49
src/Contracts/Types/Str.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 Str extends SolidityType implements IType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isType
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isType($name)
|
||||||
|
{
|
||||||
|
return (preg_match('/string(\[([0-9]+)\])*/', $name) === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isDynamicType
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDynamicType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
69
test/unit/StrTypeTest.php
Normal file
69
test/unit/StrTypeTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Test\TestCase;
|
||||||
|
use Web3\Contracts\Types\Str;
|
||||||
|
|
||||||
|
class StrTypeTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* testTypes
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $testTypes = [
|
||||||
|
[
|
||||||
|
'value' => 'string',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'string[]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'string[4]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'string[][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'string[3][]',
|
||||||
|
'result' => true
|
||||||
|
], [
|
||||||
|
'value' => 'string[][6][]',
|
||||||
|
'result' => true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* solidityType
|
||||||
|
*
|
||||||
|
* @var \Web3\Contracts\SolidityType
|
||||||
|
*/
|
||||||
|
protected $solidityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->solidityType = new Str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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