Skip to content

Commit 7f1a22e

Browse files
authored
Fixed bug that proxy class will be generated failed when using parameters who allow null in constructor.
1 parent 66d0c49 commit 7f1a22e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

tests/AstTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use HyperfTest\Di\Stub\Ast\Foo;
2424
use HyperfTest\Di\Stub\Ast\FooTrait;
2525
use HyperfTest\Di\Stub\FooEnumStruct;
26+
use HyperfTest\Di\Stub\Par2;
2627
use PHPUnit\Framework\TestCase;
2728

2829
/**
@@ -67,6 +68,28 @@ function __construct()
6768
}', $code);
6869
}
6970

71+
public function testParentWith()
72+
{
73+
$ast = new Ast();
74+
$code = $ast->proxy(Par2::class);
75+
76+
$this->assertSame($this->license . '
77+
namespace HyperfTest\Di\Stub;
78+
79+
class Par2 extends Par
80+
{
81+
use \Hyperf\Di\Aop\ProxyTrait;
82+
use \Hyperf\Di\Aop\PropertyHandlerTrait;
83+
function __construct(?\HyperfTest\Di\Stub\Foo $foo)
84+
{
85+
if (method_exists(parent::class, \'__construct\')) {
86+
parent::__construct(...func_get_args());
87+
}
88+
$this->__handlePropertyHandler(__CLASS__);
89+
}
90+
}', $code);
91+
}
92+
7093
public function testAstProxyForEnum()
7194
{
7295
if (PHP_VERSION_ID < 80100) {

tests/Stub/Par.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 Par
15+
{
16+
public function __construct(public ?Foo $foo)
17+
{
18+
}
19+
}

tests/Stub/Par2.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 Par2 extends Par
15+
{
16+
}

0 commit comments

Comments
 (0)