test(php): 添加标准容器静态类匹配测试用例

- 添加 testStdContainerStaticClassMismatch 测试方法验证对象分配错误
- 更新 StdContainerParser 中的 fatal error 消息格式保持一致性
pull/1/head
韩天峰 4 months ago
parent 872c98fc28
commit ee240aed25
  1. 8
      phpunit/src/AssignTest.php
  2. 3
      src/Php/Parser/StdContainerParser.php

@ -11,4 +11,12 @@ class AssignTest extends \BaseTest
{
$this->exec('Cannot re-assign typed object `$obj1` from `stdClass` to `ArrayObject`', 're-assign-2.php');
}
public function testStdContainerStaticClassMismatch()
{
$this->exec(
'Cannot assign object of class `StdContainerStaticChild` to std container value of class `StdContainerStaticBase`',
'std-container-static-class-mismatch.php'
);
}
}

@ -339,10 +339,9 @@ trait StdContainerParser
if ($rightClass !== $class) {
$this->fatalError($expr, "Cannot assign object of class `{$rightClass}` to std container value of class `{$class}`");
}
return $this->convertObjectExpr($valueExpr);
}
return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class). ', true)';
return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class) . ', true)';
}
protected function parseStdMapKeyType(NodeAbstract $expr, string $owner): string

Loading…
Cancel
Save