This commit is contained in:
gaofeng
2026-06-17 09:23:18 +08:00
commit 81ade70944
1638 changed files with 213697 additions and 0 deletions

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

View 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;
}
}

View 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;
}
}