This commit is contained in:
sc0Vu 2017-12-26 17:30:23 +08:00
parent 12470f3b90
commit 152d956b3d
2 changed files with 118 additions and 0 deletions

View 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
View 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']);
}
}
}