-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 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
77 changes: 77 additions & 0 deletions
77
tests/Unit/Collector/VarDumperHandlerInterfaceProxyTest.php
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,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); | ||
} | ||
} |