Skip to content

Commit

Permalink
allow passing object instance to class_uses_recursive (#15223)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarektkaczyk authored and taylorotwell committed Sep 2, 2016
1 parent ccf1724 commit 4199fb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,15 @@ function class_basename($class)
/**
* Returns all traits used by a class, its subclasses and trait of their traits.
*
* @param string $class
* @param object|string $class
* @return array
*/
function class_uses_recursive($class)
{
if (is_object($class)) {
$class = get_class($class);
}

$results = [];

foreach (array_merge([$class => $class], class_parents($class)) as $class) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,15 @@ public function testClassUsesRecursiveShouldReturnTraitsOnParentClasses()
class_uses_recursive('SupportTestClassTwo'));
}

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

public function testArrayAdd()
{
$this->assertEquals(['surname' => 'Mövsümov'], array_add([], 'surname', 'Mövsümov'));
Expand Down

0 comments on commit 4199fb0

Please sign in to comment.