提交
This commit is contained in:
80
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/AnnotationTest.php
vendored
Normal file
80
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/AnnotationTest.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace UnitTests\Annotation;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'XmlObject.php';
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'ModelObject.php';
|
||||
|
||||
use AlibabaCloud\Oss\V2\Annotation\Functions;
|
||||
|
||||
class AnnotationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testXmlAnnotation()
|
||||
{
|
||||
$obj = new XmlObject();
|
||||
$ro = new \ReflectionObject($obj);
|
||||
$attributes = $ro->getAttributes();
|
||||
$this->assertCount(1, $attributes);
|
||||
$inst = $attributes[0]->newInstance();
|
||||
$this->assertNotNull($inst);
|
||||
$this->assertEquals("XmlRoot", $inst->name);
|
||||
|
||||
$prop = $ro->getProperty("strValue");
|
||||
$this->assertNotNull($prop);
|
||||
$attributes = $prop->getAttributes();
|
||||
$this->assertCount(1, $attributes);
|
||||
$inst = $attributes[0]->newInstance();
|
||||
$this->assertNotNull($inst);
|
||||
$this->assertEquals("StrValue", $inst->rename);
|
||||
$this->assertEquals("string", $inst->type);
|
||||
|
||||
$prop = $ro->getProperty("strValueLists");
|
||||
$this->assertNotNull($prop);
|
||||
$attributes = $prop->getAttributes();
|
||||
$this->assertCount(1, $attributes);
|
||||
$inst = $attributes[0]->newInstance();
|
||||
$this->assertNotNull($inst);
|
||||
$this->assertEquals("StrValueList", $inst->rename);
|
||||
$this->assertEquals("string", $inst->type);
|
||||
}
|
||||
|
||||
public function testRequiredProperty()
|
||||
{
|
||||
$obj = new ModelObject();
|
||||
$ro = new \ReflectionObject($obj);
|
||||
|
||||
$prop = $ro->getProperty("strValue");
|
||||
$this->assertNotNull($prop);
|
||||
$this->assertTrue(Functions::isRequiredProperty($prop));
|
||||
|
||||
$prop = $ro->getProperty("intValue");
|
||||
$this->assertNotNull($prop);
|
||||
$this->assertFalse(Functions::isRequiredProperty($prop));
|
||||
}
|
||||
|
||||
public function testFunctions()
|
||||
{
|
||||
$obj = new ModelObject();
|
||||
$ro = new \ReflectionObject($obj);
|
||||
|
||||
$prop = $ro->getProperty("strValue");
|
||||
$this->assertNotNull($prop);
|
||||
|
||||
$result = Functions::getXmlElementAnnotation($prop);
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = Functions::getTagAnnotation($prop);
|
||||
$this->assertNotNull($result);
|
||||
$this->assertEquals("input", $result->tag);
|
||||
$this->assertEquals("nop", $result->position);
|
||||
$this->assertEquals("StrValue", $result->rename);
|
||||
$this->assertEquals("string", $result->type);
|
||||
|
||||
$result = Functions::getPropertyAnnotations($prop);
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
$this->assertEquals("input", $result[1]->tag);
|
||||
$this->assertEquals("nop", $result[1]->position);
|
||||
$this->assertEquals("StrValue", $result[1]->rename);
|
||||
$this->assertEquals("string", $result[1]->type);
|
||||
}
|
||||
}
|
||||
39
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/ModelObject.php
vendored
Normal file
39
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/ModelObject.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\Annotation;
|
||||
|
||||
use AlibabaCloud\Oss\V2\Annotation\TagProperty;
|
||||
use AlibabaCloud\Oss\V2\Annotation\RequiredProperty;
|
||||
|
||||
class ModelObject
|
||||
{
|
||||
#[RequiredProperty()]
|
||||
#[TagProperty(tag: 'input', position: 'nop', rename:'StrValue', type: 'string')]
|
||||
public ?string $strValue;
|
||||
|
||||
#[TagProperty(tag: 'input', position: 'nop', rename:'IntValue', type: 'int')]
|
||||
public ?int $intValue;
|
||||
|
||||
#[TagProperty(tag: 'input', position: 'nop', rename:'BoolValue', type: 'bool')]
|
||||
public ?bool $boolValue;
|
||||
|
||||
#[TagProperty(tag: 'input', position: 'nop', rename:'FloatValue', type: 'float')]
|
||||
public ?float $floatValue;
|
||||
|
||||
#[TagProperty(tag: 'input', position: 'nop', rename:'StrValueList', type: 'string')]
|
||||
public ?array $strValueLists;
|
||||
|
||||
public function __construct(
|
||||
?string $strValue = null,
|
||||
?int $intValue = null,
|
||||
?bool $boolValue = null,
|
||||
?float $floatValue = null,
|
||||
?array $strValueLists = null
|
||||
) {
|
||||
$this->strValue = $strValue;
|
||||
$this->intValue = $intValue;
|
||||
$this->boolValue = $boolValue;
|
||||
$this->floatValue = $floatValue;
|
||||
$this->strValueLists = $strValueLists;
|
||||
}
|
||||
}
|
||||
39
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/XmlObject.php
vendored
Normal file
39
vendor/alibabacloud/oss-v2/tests/UnitTests/Annotation/XmlObject.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace UnitTests\Annotation;
|
||||
|
||||
use AlibabaCloud\Oss\V2\Annotation\XmlElement;
|
||||
use AlibabaCloud\Oss\V2\Annotation\XmlRoot;
|
||||
|
||||
#[XmlRoot(name:'XmlRoot')]
|
||||
class XmlObject
|
||||
{
|
||||
#[XmlElement(rename:'StrValue', type: 'string')]
|
||||
public ?string $strValue;
|
||||
|
||||
#[XmlElement(rename:'IntValue', type: 'int')]
|
||||
public ?int $intValue;
|
||||
|
||||
#[XmlElement(rename:'BoolValue', type: 'bool')]
|
||||
public ?bool $boolValue;
|
||||
|
||||
#[XmlElement(rename:'FloatValue', type: 'float')]
|
||||
public ?float $floatValue;
|
||||
|
||||
#[XmlElement(rename:'StrValueList', type: 'string')]
|
||||
public ?array $strValueLists;
|
||||
|
||||
public function __construct(
|
||||
?string $strValue = null,
|
||||
?int $intValue = null,
|
||||
?bool $boolValue = null,
|
||||
?float $floatValue = null,
|
||||
?array $strValueLists = null
|
||||
) {
|
||||
$this->strValue = $strValue;
|
||||
$this->intValue = $intValue;
|
||||
$this->boolValue = $boolValue;
|
||||
$this->floatValue = $floatValue;
|
||||
$this->strValueLists = $strValueLists;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user