Skip to content

Commit 0f2b069

Browse files
committed
Merge branch 'master' into 3.1
# Conflicts: # src/support/tests/FunctionTest.php
2 parents 55da1b8 + e3690f0 commit 0f2b069

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

src/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

tests/FunctionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
namespace HyperfTest\Support;
1313

1414
use HyperfTest\Support\Exception\RetryException;
15+
use HyperfTest\Support\Stub\Bar;
16+
use HyperfTest\Support\Stub\Foo;
1517
use HyperfTest\Support\Stub\FooClosure;
18+
use HyperfTest\Support\Stub\Traits\BarTrait;
19+
use HyperfTest\Support\Stub\Traits\FooTrait;
1620
use PHPUnit\Framework\Attributes\CoversNothing;
1721
use PHPUnit\Framework\TestCase;
1822

1923
use function Hyperf\Support\call;
24+
use function Hyperf\Support\class_uses_recursive;
2025
use function Hyperf\Support\env;
2126
use function Hyperf\Support\retry;
2227
use 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
}

tests/Stub/Bar.php

Lines changed: 19 additions & 0 deletions
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 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+
}

tests/Stub/Foo.php

Lines changed: 19 additions & 0 deletions
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 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+
}

tests/Stub/Traits/BarTrait.php

Lines changed: 16 additions & 0 deletions
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 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+
}

tests/Stub/Traits/FooTrait.php

Lines changed: 16 additions & 0 deletions
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 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+
}

0 commit comments

Comments
 (0)