TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
<?php
|
|
|
|
use PhpAot\Php\CompilerTest;
|
|
use PhpAot\Php\Exception\TestError;
|
|
|
|
class CompilerPhaseProbe extends CompilerTest
|
|
{
|
|
public static function createProbe(string $rootPath): self
|
|
{
|
|
$compiler = new self($rootPath);
|
|
$compiler->forTest = true;
|
|
return $compiler;
|
|
}
|
|
|
|
public function enterPreparePhase(): void
|
|
{
|
|
$this->enterCompilerPhase(self::PHASE_PREPARE);
|
|
}
|
|
|
|
public function enterConvertPhase(): void
|
|
{
|
|
$this->enterCompilerPhase(self::PHASE_CONVERT);
|
|
}
|
|
|
|
public function probePropertyAccessResolver(): bool
|
|
{
|
|
return $this->canAccessProtectedProperty('ProbeClass', 'ProbeClass');
|
|
}
|
|
}
|
|
|
|
class CompilerPhaseTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public function testPropertyAccessResolverCannotBeUsedOutsideConvertPhase(): void
|
|
{
|
|
$compiler = CompilerPhaseProbe::createProbe(ROOT_PATH);
|
|
|
|
$this->expectException(TestError::class);
|
|
$this->expectExceptionMessage('PropertyAccessResolver can only be used during convert phase');
|
|
|
|
$compiler->probePropertyAccessResolver();
|
|
}
|
|
|
|
public function testPropertyAccessResolverCannotBeUsedDuringPreparePhase(): void
|
|
{
|
|
$compiler = CompilerPhaseProbe::createProbe(ROOT_PATH);
|
|
$compiler->enterPreparePhase();
|
|
|
|
$this->expectException(TestError::class);
|
|
$this->expectExceptionMessage('PropertyAccessResolver can only be used during convert phase');
|
|
|
|
$compiler->probePropertyAccessResolver();
|
|
}
|
|
|
|
public function testPropertyAccessResolverCanBeUsedDuringConvertPhase(): void
|
|
{
|
|
$compiler = CompilerPhaseProbe::createProbe(ROOT_PATH);
|
|
$compiler->enterConvertPhase();
|
|
|
|
$this->assertTrue($compiler->probePropertyAccessResolver());
|
|
}
|
|
}
|
|
|