File tree Expand file tree Collapse file tree 6 files changed +93
-1
lines changed Expand file tree Collapse file tree 6 files changed +93
-1
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ function class_uses_recursive($class)
159159 $ results = [];
160160
161161 /* @phpstan-ignore-next-line */
162- foreach (array_reverse (class_parents ($ class )) + [$ class => $ class ] as $ class ) {
162+ foreach (array_reverse (class_parents ($ class ) ?: [] ) + [$ class => $ class ] as $ class ) {
163163 $ results += trait_uses_recursive ($ class );
164164 }
165165
Original file line number Diff line number Diff line change 1212namespace HyperfTest \Support ;
1313
1414use HyperfTest \Support \Exception \RetryException ;
15+ use HyperfTest \Support \Stub \Bar ;
16+ use HyperfTest \Support \Stub \Foo ;
1517use HyperfTest \Support \Stub \FooClosure ;
18+ use HyperfTest \Support \Stub \Traits \BarTrait ;
19+ use HyperfTest \Support \Stub \Traits \FooTrait ;
1620use PHPUnit \Framework \Attributes \CoversNothing ;
1721use PHPUnit \Framework \TestCase ;
1822
1923use function Hyperf \Support \call ;
24+ use function Hyperf \Support \class_uses_recursive ;
2025use function Hyperf \Support \env ;
2126use function Hyperf \Support \retry ;
2227use function Hyperf \Support \swoole_hook_flags ;
@@ -130,4 +135,21 @@ public function testEnv()
130135
131136 $ this ->assertNull (env ($ id ));
132137 }
138+
139+ public function testClassUsesRecursive ()
140+ {
141+ $ this ->assertSame (
142+ [
143+ FooTrait::class => FooTrait::class,
144+ ],
145+ class_uses_recursive (Foo::class)
146+ );
147+ $ this ->assertSame (
148+ [
149+ FooTrait::class => FooTrait::class,
150+ BarTrait::class => BarTrait::class,
151+ ],
152+ class_uses_recursive (Bar::class)
153+ );
154+ }
133155}
Original file line number Diff line number Diff line change 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 group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+ namespace HyperfTest \Support \Stub ;
13+
14+ use HyperfTest \Support \Stub \Traits \BarTrait ;
15+
16+ class Bar extends Foo
17+ {
18+ use BarTrait;
19+ }
Original file line number Diff line number Diff line change 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 group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+ namespace HyperfTest \Support \Stub ;
13+
14+ use HyperfTest \Support \Stub \Traits \FooTrait ;
15+
16+ class Foo
17+ {
18+ use FooTrait;
19+ }
Original file line number Diff line number Diff line change 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 group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+ namespace HyperfTest \Support \Stub \Traits ;
13+
14+ trait BarTrait
15+ {
16+ }
Original file line number Diff line number Diff line change 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 group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+ namespace HyperfTest \Support \Stub \Traits ;
13+
14+ trait FooTrait
15+ {
16+ }
You can’t perform that action at this time.
0 commit comments