- 将 std::vector 的类值类型精确匹配测试添加到测试套件 - 修复 std::map 错误消息格式以显示正确的参数对象类型验证 - 添加 std::unordered_map 的类值类型精确匹配测试用例 - 添加 std::array 的类值类型精确匹配测试用例 - 简化 StdContainerParser 中的对象转换逻辑,使用统一的 toObject 方法进行类型检查和转换pull/1/head
parent
9f2db2f6c0
commit
872c98fc28
5 changed files with 135 additions and 6 deletions
@ -0,0 +1,44 @@ |
||||
--TEST-- |
||||
std array: exact class value type |
||||
--FILE-- |
||||
<?php |
||||
class StdArrayClassValue |
||||
{ |
||||
public function __construct(public int $value) |
||||
{ |
||||
} |
||||
|
||||
public function getValue(): int |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
||||
|
||||
class StdArrayClassValueChild extends StdArrayClassValue |
||||
{ |
||||
} |
||||
|
||||
function std_array_class_value_mixed(mixed $value): mixed |
||||
{ |
||||
return $value; |
||||
} |
||||
|
||||
function main() { |
||||
$array = std::array(StdArrayClassValue::class, 3); |
||||
$array[0] = new StdArrayClassValue(1); |
||||
var_dump($array[0]->getValue()); |
||||
|
||||
$array[1] = std_array_class_value_mixed(new StdArrayClassValue(2)); |
||||
var_dump($array[1]->getValue()); |
||||
|
||||
try { |
||||
$array[2] = std_array_class_value_mixed(new StdArrayClassValueChild(3)); |
||||
} catch (Throwable $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
int(2) |
||||
The parameter `object` must be instance of class `StdArrayClassValue`, object of `StdArrayClassValueChild` given |
||||
@ -0,0 +1,44 @@ |
||||
--TEST-- |
||||
std unordered map: exact class value type |
||||
--FILE-- |
||||
<?php |
||||
class StdUnorderedMapClassValue |
||||
{ |
||||
public function __construct(public int $value) |
||||
{ |
||||
} |
||||
|
||||
public function getValue(): int |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
||||
|
||||
class StdUnorderedMapClassValueChild extends StdUnorderedMapClassValue |
||||
{ |
||||
} |
||||
|
||||
function std_unordered_map_class_value_mixed(mixed $value): mixed |
||||
{ |
||||
return $value; |
||||
} |
||||
|
||||
function main() { |
||||
$map = std::unordered_map(complex_types::type_str, StdUnorderedMapClassValue::class); |
||||
$map["a"] = new StdUnorderedMapClassValue(1); |
||||
var_dump($map["a"]->getValue()); |
||||
|
||||
$map["b"] = std_unordered_map_class_value_mixed(new StdUnorderedMapClassValue(2)); |
||||
var_dump($map["b"]->getValue()); |
||||
|
||||
try { |
||||
$map["c"] = std_unordered_map_class_value_mixed(new StdUnorderedMapClassValueChild(3)); |
||||
} catch (Throwable $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
int(2) |
||||
The parameter `object` must be instance of class `StdUnorderedMapClassValue`, object of `StdUnorderedMapClassValueChild` given |
||||
@ -0,0 +1,44 @@ |
||||
--TEST-- |
||||
std vector: exact class value type |
||||
--FILE-- |
||||
<?php |
||||
class StdVectorClassValue |
||||
{ |
||||
public function __construct(public int $value) |
||||
{ |
||||
} |
||||
|
||||
public function getValue(): int |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
||||
|
||||
class StdVectorClassValueChild extends StdVectorClassValue |
||||
{ |
||||
} |
||||
|
||||
function std_vector_class_value_mixed(mixed $value): mixed |
||||
{ |
||||
return $value; |
||||
} |
||||
|
||||
function main() { |
||||
$vector = std::vector(StdVectorClassValue::class); |
||||
$vector[] = new StdVectorClassValue(1); |
||||
var_dump($vector[0]->getValue()); |
||||
|
||||
$vector[] = std_vector_class_value_mixed(new StdVectorClassValue(2)); |
||||
var_dump($vector[1]->getValue()); |
||||
|
||||
try { |
||||
$vector[] = std_vector_class_value_mixed(new StdVectorClassValueChild(3)); |
||||
} catch (Throwable $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
int(2) |
||||
The parameter `object` must be instance of class `StdVectorClassValue`, object of `StdVectorClassValueChild` given |
||||
Loading…
Reference in new issue