Skip to content

Commit 8935c54

Browse files
committed
Added proxy class generate testing.
1 parent 165e0fa commit 8935c54

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

tests/AstTest.php

+44
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use HyperfTest\Di\Stub\AspectCollector;
1616
use HyperfTest\Di\Stub\Ast\Bar2;
1717
use HyperfTest\Di\Stub\Ast\Bar3;
18+
use HyperfTest\Di\Stub\Ast\Bar4;
1819
use HyperfTest\Di\Stub\Ast\BarAspect;
1920
use HyperfTest\Di\Stub\Ast\Foo;
2021
use PHPUnit\Framework\TestCase;
@@ -119,6 +120,49 @@ public function getId() : int
119120
return Bar::getId();
120121
});
121122
}
123+
}', $code);
124+
}
125+
126+
public function testRewriteParent()
127+
{
128+
$ast = new Ast();
129+
$proxyClass = Bar4::class . 'Proxy';
130+
$code = $ast->proxy(Bar4::class, $proxyClass);
131+
132+
$this->assertEquals('<?php
133+
134+
declare (strict_types=1);
135+
/**
136+
* This file is part of Hyperf.
137+
*
138+
* @link https://www.hyperf.io
139+
* @document https://doc.hyperf.io
140+
* @contact [email protected]
141+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
142+
*/
143+
namespace HyperfTest\Di\Stub\Ast;
144+
145+
class Bar4Proxy extends Bar4
146+
{
147+
use \Hyperf\Di\Aop\ProxyTrait;
148+
public function __construct(int $id)
149+
{
150+
Bar::__construct($id);
151+
}
152+
public function getId() : int
153+
{
154+
return Bar::getId();
155+
}
156+
public static function getItems()
157+
{
158+
return Bar::$items;
159+
}
160+
public function closure()
161+
{
162+
value(function () {
163+
Bar::getId();
164+
});
165+
}
122166
}', $code);
123167
}
124168
}

tests/Stub/Ast/Bar4.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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://doc.hyperf.io
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
13+
namespace HyperfTest\Di\Stub\Ast;
14+
15+
class Bar4 extends Bar
16+
{
17+
public function __construct(int $id)
18+
{
19+
parent::__construct($id);
20+
}
21+
22+
public function getId(): int
23+
{
24+
return parent::getId();
25+
}
26+
27+
public static function getItems()
28+
{
29+
return parent::$items;
30+
}
31+
32+
public function closure()
33+
{
34+
value(function () {
35+
parent::getId();
36+
});
37+
}
38+
}

0 commit comments

Comments
 (0)