Skip to content

Commit 66d0c49

Browse files
authored
Support the transformation of object type to AST nodes. (#5206)
1 parent 56c1b11 commit 66d0c49

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/AstTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use HyperfTest\Di\Stub\Ast\BarInterface;
2323
use HyperfTest\Di\Stub\Ast\Foo;
2424
use HyperfTest\Di\Stub\Ast\FooTrait;
25+
use HyperfTest\Di\Stub\FooEnumStruct;
2526
use PHPUnit\Framework\TestCase;
2627

2728
/**
@@ -66,6 +67,29 @@ function __construct()
6667
}', $code);
6768
}
6869

70+
public function testAstProxyForEnum()
71+
{
72+
if (PHP_VERSION_ID < 80100) {
73+
$this->markTestSkipped('The version below 8.1 does not support enum.');
74+
}
75+
76+
$ast = new Ast();
77+
$code = $ast->proxy(FooEnumStruct::class);
78+
79+
$this->assertEquals($this->license . '
80+
namespace HyperfTest\Di\Stub;
81+
82+
class FooEnumStruct
83+
{
84+
use \Hyperf\Di\Aop\ProxyTrait;
85+
use \Hyperf\Di\Aop\PropertyHandlerTrait;
86+
public function __construct(public FooEnum $enum = FooEnum::DEFAULT)
87+
{
88+
$this->__handlePropertyHandler(__CLASS__);
89+
}
90+
}', $code);
91+
}
92+
6993
public function testParentMethods()
7094
{
7195
$ast = new Ast();

tests/Stub/FooEnum.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\Di\Stub;
13+
14+
enum FooEnum: int
15+
{
16+
case DEFAULT = 1;
17+
}

tests/Stub/FooEnumStruct.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\Di\Stub;
13+
14+
class FooEnumStruct
15+
{
16+
public function __construct(public FooEnum $enum = FooEnum::DEFAULT)
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)