Skip to content

Commit

Permalink
interfacing CallTraceFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Jul 31, 2021
1 parent c92fdd9 commit 429b187
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
3 changes: 3 additions & 0 deletions config/di.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoop;
use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoopInterface;
use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
use PhpProfiler\Inspector\Output\TraceFormatter\Dumb\DumbCallTraceFormatter;
use PhpProfiler\Lib\Amphp\ContextCreator;
use PhpProfiler\Lib\Amphp\ContextCreatorInterface;
use PhpProfiler\Lib\ByteStream\IntegerByteSequence\IntegerByteSequenceReader;
Expand Down Expand Up @@ -43,4 +45,5 @@
->constructorParameter('di_config_file', __DIR__ . '/di.php'),
PhpReaderTraceLoopInterface::class => autowire(PhpReaderTraceLoop::class),
ProcessSearcherInterface::class => autowire(ProcessSearcher::class),
CallTraceFormatter::class => autowire(DumbCallTraceFormatter::class),
];
2 changes: 1 addition & 1 deletion src/Command/Inspector/DaemonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use PhpProfiler\Inspector\Daemon\Dispatcher\WorkerPool;
use PhpProfiler\Inspector\Daemon\Reader\Context\PhpReaderContextCreator;
use PhpProfiler\Inspector\Daemon\Searcher\Context\PhpSearcherContextCreator;
use PhpProfiler\Inspector\Output\CallTraceFormatter;
use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
use PhpProfiler\Inspector\Settings\DaemonSettings\DaemonSettingsFromConsoleInput;
use PhpProfiler\Inspector\Settings\GetTraceSettings\GetTraceSettingsFromConsoleInput;
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettingsFromConsoleInput;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Inspector/GetTraceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace PhpProfiler\Command\Inspector;

use PhpProfiler\Inspector\Output\CallTraceFormatter;
use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
use PhpProfiler\Inspector\Settings\GetTraceSettings\GetTraceSettingsFromConsoleInput;
use PhpProfiler\Inspector\Settings\InspectorSettingsException;
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettingsFromConsoleInput;
Expand Down
21 changes: 21 additions & 0 deletions src/Inspector/Output/TraceFormatter/CallTraceFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output\TraceFormatter;

use PhpProfiler\Lib\PhpProcessReader\CallTrace;

interface CallTraceFormatter
{
public function format(CallTrace $call_trace): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;

use PhpProfiler\Lib\PhpProcessReader\CallFrame;

final class CallFrameFormatter
final class DumbCallFrameFormatter
{
public function format(CallFrame $call_frame): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;

use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
use PhpProfiler\Lib\PhpProcessReader\CallTrace;

final class CallTraceFormatter
final class DumbCallTraceFormatter implements CallTraceFormatter
{
private CallFrameFormatter $call_frame_formatter;
private DumbCallFrameFormatter $call_frame_formatter;

public function __construct(
CallFrameFormatter $call_frame_formatter
DumbCallFrameFormatter $call_frame_formatter
) {
$this->call_frame_formatter = $call_frame_formatter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;

use PhpProfiler\Lib\PhpInternals\Types\Zend\Opline;
use PhpProfiler\Lib\PhpProcessReader\CallFrame;
use PhpProfiler\Lib\PhpProcessReader\CallTrace;
use PHPUnit\Framework\TestCase;

class CallTraceFormatterTest extends TestCase
class DumbCallTraceFormatterTest extends TestCase
{
/** @dataProvider dataProvider */
public function testFormat(string $expects, CallTrace $call_trace): void
{
$formatter = new CallTraceFormatter(new CallFrameFormatter());
$formatter = new DumbCallTraceFormatter(new DumbCallFrameFormatter());
$this->assertSame($expects, $formatter->format($call_trace));
}

Expand Down

0 comments on commit 429b187

Please sign in to comment.