-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent recording of child spans of a 'leaf' span
Showing
6 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Scoutapm\UnitTests; | ||
|
||
use InvalidArgumentException; | ||
use ReflectionException; | ||
use ReflectionProperty; | ||
use Scoutapm\Connector\Command; | ||
use Scoutapm\Connector\CommandWithChildren; | ||
use Webmozart\Assert\Assert; | ||
|
||
use function count; | ||
use function reset; | ||
|
||
final class TestHelper | ||
{ | ||
/** | ||
* @return Command[] | ||
* | ||
* @throws InvalidArgumentException|ReflectionException | ||
*/ | ||
public static function childrenForCommand(CommandWithChildren $commandWithChildren): array | ||
{ | ||
$childrenProperty = new ReflectionProperty($commandWithChildren, 'children'); | ||
$childrenProperty->setAccessible(true); | ||
$children = $childrenProperty->getValue($commandWithChildren); | ||
|
||
Assert::isArray($children); | ||
Assert::allIsInstanceOf($children, Command::class); | ||
|
||
return $children; | ||
} | ||
|
||
public static function firstChildForCommand(CommandWithChildren $commandWithChildren): Command | ||
{ | ||
$children = self::childrenForCommand($commandWithChildren); | ||
|
||
Assert::greaterThanEq(count($children), 1); | ||
|
||
return reset($children); | ||
} | ||
} |