refactor(tests): 替换 objval 函数调用为 toObject 方法

- 移除了全局 objval 函数实现
- 将所有测试文件中的 objval($obj, Class::class) 替换为 $obj->toObject(Class::class)
- 更新了 std-vector、std-map、std-unordered-map、std-array 和 type_decl 测试
- 添加了新的 var_convert 链式调用测试用例
- 统一了对象类型转换的调用方式
pull/1/head
韩天峰 3 months ago
parent 275ef95da7
commit a4d28fbe6b
  1. 7
      src/polyfills.php
  2. 4
      tests/aot/basic/objval.phpt
  3. 2
      tests/aot/std-array/005.phpt
  4. 2
      tests/aot/std-map/003.phpt
  5. 2
      tests/aot/std-unordered-map/003.phpt
  6. 2
      tests/aot/std-vector/002.phpt
  7. 2
      tests/aot/type_decl/007.phpt
  8. 19
      tests/aot/var_convert/001.phpt

@ -83,13 +83,6 @@ class std
}
}
function objval(mixed $obj, string $class): object
{
if ($obj instanceof $class) {
return $obj;
}
throw new Exception('Invalid object type');
}
function &refval(&$var)
{

@ -25,10 +25,10 @@ function main()
$obj = new TestObjval(1, 2);
$arr = array();
$arr['obj'] = $obj;
$obj2 = objval($arr['obj'], 'TestObjval');
$obj2 = $arr['obj']->toObject('TestObjval');
var_dump($obj2->test());
$obj3 = objval($obj, TestObjval::class);
$obj3 = $obj->toObject(TestObjval::class);
var_dump($obj3->test());
}
?>

@ -28,7 +28,7 @@ function main() {
$objects = std::array(complex_types::type_object, 2);
$objects[0] = new StdArrayComplexValue(28);
var_dump($objects[0] instanceof StdArrayComplexValue);
$object = objval($objects[0], StdArrayComplexValue::class);
$object = $objects[0]->toObject(StdArrayComplexValue::class);
var_dump($object->getValue());
$variants = std::array(complex_types::type_any, 2);

@ -28,7 +28,7 @@ function main() {
$objects = std::map(complex_types::type_string, complex_types::type_object);
$objects["item"] = new StdMapComplexValue(14);
var_dump($objects["item"] instanceof StdMapComplexValue);
$object = objval($objects["item"], StdMapComplexValue::class);
$object = $objects["item"]->toObject(StdMapComplexValue::class);
var_dump($object->getValue());
$variants = std::map(native_types::type_int, complex_types::type_any);

@ -28,7 +28,7 @@ function main() {
$objects = std::unordered_map(native_types::type_int, complex_types::type_object);
$objects[2] = new StdUnorderedMapComplexValue(21);
var_dump($objects[2] instanceof StdUnorderedMapComplexValue);
$object = objval($objects[2], StdUnorderedMapComplexValue::class);
$object = $objects[2]->toObject(StdUnorderedMapComplexValue::class);
var_dump($object->getValue());
$variants = std::unordered_map(native_types::type_int, complex_types::type_var);

@ -28,7 +28,7 @@ function main() {
$objects = std::vector(complex_types::type_object);
$objects[] = new StdVectorComplexValue(7);
var_dump($objects[0] instanceof StdVectorComplexValue);
$object = objval($objects[0], StdVectorComplexValue::class);
$object = $objects[0]->toObject(StdVectorComplexValue::class);
var_dump($object->getValue());
$variants = std::vector(complex_types::type_variant);

@ -18,7 +18,7 @@ namespace TestApp\Command {
public function callCommand(string $class): Command
{
$array = ['object' => new Command($class)];
return objval($array['object'], Command::class);
return $array['object']->toObject(Command::class);
}
}
}

@ -0,0 +1,19 @@
--TEST--
var convert chained on array element
--FILE--
<?php
use native_types;
function main()
{
$arr = [];
$name = "hello";
$arr["name"] = $name;
$arr["age"] = 20;
var_dump($arr["age"]->toString());
var_dump($arr["name"]->toString());
}
?>
--EXPECT--
string(2) "20"
string(5) "hello"
Loading…
Cancel
Save