- 实现了对变量重新赋值时的类型验证逻辑 - 当变量从一种类型重新赋值为另一种类型时抛出致命错误 - 添加了测试基类用于编译器测试 - 新增变量重新赋值的单元测试用例 - 在代码差异中检测到变量类型变化时触发错误处理pull/1/head
parent
1a7bfe1de5
commit
a1c922dac2
4 changed files with 44 additions and 0 deletions
@ -1,4 +1,25 @@ |
||||
<?php |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
use PhpAot\Php\CompilerTest; |
||||
use PhpAot\Php\Exception\TestError; |
||||
|
||||
require __DIR__ . '/../bin/bootstrap.php'; |
||||
|
||||
class BaseTest extends TestCase |
||||
{ |
||||
protected function exec(string $expected, string $file): void |
||||
{ |
||||
try { |
||||
$compiler = CompilerTest::create(ROOT_PATH); |
||||
$testFile = __DIR__ . '/code/' . $file; |
||||
$compiler->addFiles([$testFile]); |
||||
$compiler->prepare($testFile); |
||||
$compiler->convert($testFile); |
||||
} catch (TestError $exception) { |
||||
$this->assertStringContainsString($expected, $exception->getMessage()); |
||||
return; |
||||
} |
||||
$this->fail(); |
||||
} |
||||
} |
||||
@ -0,0 +1,6 @@ |
||||
<?php |
||||
function main() |
||||
{ |
||||
$obj = new stdClass(); |
||||
$obj = "hello world"; |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
<?php |
||||
|
||||
class AssignTest extends \BaseTest |
||||
{ |
||||
public function testReAssign() |
||||
{ |
||||
$this->exec('Cannot re-assign variable', 're-assign.php'); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue