Skip to content

Commit

Permalink
Proxy calls for var-dumper proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Sep 8, 2024
1 parent caefb47 commit e492e81
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Collector/VarDumperHandlerInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Yiisoft\Yii\Debug\Collector;

use Yiisoft\VarDumper\HandlerInterface;
use Yiisoft\Yii\Debug\ProxyDecoratedCalls;

final class VarDumperHandlerInterfaceProxy implements HandlerInterface
{
use ProxyDecoratedCalls;

public function __construct(
private readonly HandlerInterface $decorated,
private readonly VarDumperCollector $collector,
Expand Down
77 changes: 77 additions & 0 deletions tests/Unit/Collector/VarDumperHandlerInterfaceProxyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;

use PHPUnit\Framework\TestCase;
use stdClass;
use Yiisoft\VarDumper\HandlerInterface;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Collector\VarDumperCollector;
use Yiisoft\Yii\Debug\Collector\VarDumperHandlerInterfaceProxy;

final class VarDumperHandlerInterfaceProxyTest extends TestCase
{
public function testMethodHandle(): void
{
$handler = $this->createMock(HandlerInterface::class);
$handler
->expects($this->once())
->method('handle');
$timeline = new TimelineCollector();
$timeline->startup();
$collector = new VarDumperCollector($timeline);
$collector->startup();
$proxy = new VarDumperHandlerInterfaceProxy($handler, $collector);

$proxy->handle(true, 50, true);

$this->assertEquals([
[
'variable' => true,
'line' => __FILE__ . ':28',
],
], $collector->getCollected());
$this->assertEquals([
'var-dumper' => [
'total' => 1,
],
], $collector->getSummary());

$this->assertCount(1, $timeline->getCollected());

$event = $timeline->getCollected()[0];
$this->assertEquals(1, $event[1]);
$this->assertEquals(VarDumperCollector::class, $event[2]);
$this->assertEquals([], $event[3]);
}

public function testProxyDecoratedCall(): void
{
$handler = new class () implements HandlerInterface {
public $var = null;

public function getProxiedCall(): string
{
return 'ok';
}

public function setProxiedCall($args): mixed
{
return $args;
}

public function handle(mixed $variable, int $depth, bool $highlight = false): void
{
}
};
$collector = new VarDumperCollector(new TimelineCollector());
$proxy = new VarDumperHandlerInterfaceProxy($handler, $collector);

$this->assertEquals('ok', $proxy->getProxiedCall());
$this->assertEquals($args = [1, new stdClass(), 'string'], $proxy->setProxiedCall($args));
$proxy->var = '123';
$this->assertEquals('123', $proxy->var);
}
}

0 comments on commit e492e81

Please sign in to comment.