Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] class_uses_recursive() return parent class's trait first #22536

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function class_uses_recursive($class)

$results = [];

foreach (array_merge([$class => $class], class_parents($class)) as $class) {
foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
$results += trait_uses_recursive($class);
}

Expand Down
27 changes: 23 additions & 4 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,22 +699,32 @@ public function testLast()

public function testClassUsesRecursiveShouldReturnTraitsOnParentClasses()
{
$this->assertEquals([
'Illuminate\Tests\Support\SupportTestTraitOne' => 'Illuminate\Tests\Support\SupportTestTraitOne',
$this->assertSame([
'Illuminate\Tests\Support\SupportTestTraitTwo' => 'Illuminate\Tests\Support\SupportTestTraitTwo',
'Illuminate\Tests\Support\SupportTestTraitOne' => 'Illuminate\Tests\Support\SupportTestTraitOne',
],
class_uses_recursive('Illuminate\Tests\Support\SupportTestClassTwo'));
}

public function testClassUsesRecursiveAcceptsObject()
{
$this->assertEquals([
'Illuminate\Tests\Support\SupportTestTraitOne' => 'Illuminate\Tests\Support\SupportTestTraitOne',
$this->assertSame([
'Illuminate\Tests\Support\SupportTestTraitTwo' => 'Illuminate\Tests\Support\SupportTestTraitTwo',
'Illuminate\Tests\Support\SupportTestTraitOne' => 'Illuminate\Tests\Support\SupportTestTraitOne',
],
class_uses_recursive(new SupportTestClassTwo));
}

public function testClassUsesRecursiveReturnParentTraitsFirst()
{
$this->assertSame([
'Illuminate\Tests\Support\SupportTestTraitTwo' => 'Illuminate\Tests\Support\SupportTestTraitTwo',
'Illuminate\Tests\Support\SupportTestTraitOne' => 'Illuminate\Tests\Support\SupportTestTraitOne',
'Illuminate\Tests\Support\SupportTestTraitThree' => 'Illuminate\Tests\Support\SupportTestTraitThree',
],
class_uses_recursive(SupportTestClassThree::class));
}

public function testArrayAdd()
{
$this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov'));
Expand Down Expand Up @@ -845,6 +855,15 @@ class SupportTestClassTwo extends SupportTestClassOne
{
}

trait SupportTestTraitThree
{
}

class SupportTestClassThree extends SupportTestClassTwo
{
use SupportTestTraitThree;
}

class SupportTestArrayAccess implements ArrayAccess
{
protected $attributes = [];
Expand Down