-
-
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
5 changed files
with
113 additions
and
12 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
35 changes: 35 additions & 0 deletions
35
tests/Unit/Collector/EventDispatcherInterfaceProxyTest.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Tests\Unit\Collector; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use stdClass; | ||
use Yiisoft\Yii\Debug\Collector\EventCollector; | ||
use Yiisoft\Yii\Debug\Collector\EventDispatcherInterfaceProxy; | ||
use Yiisoft\Yii\Debug\Collector\TimelineCollector; | ||
|
||
final class EventDispatcherInterfaceProxyTest extends TestCase | ||
{ | ||
public function testDispatch() | ||
{ | ||
$event = new stdClass(); | ||
$collector = new EventCollector(new TimelineCollector()); | ||
$collector->startup(); | ||
|
||
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); | ||
$eventDispatcherMock | ||
->expects($this->once()) | ||
->method('dispatch') | ||
->with($event) | ||
->willReturn($event); | ||
$eventDispatcher = new EventDispatcherInterfaceProxy($eventDispatcherMock, $collector); | ||
|
||
$newEvent = $eventDispatcher->dispatch($event); | ||
|
||
$this->assertSame($event, $newEvent); | ||
$this->assertCount(1, $collector->getCollected()); | ||
} | ||
} |
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 Yiisoft\Yii\Debug\Tests\Unit\Collector; | ||
|
||
use Yiisoft\Yii\Debug\Collector\CollectorInterface; | ||
use Yiisoft\Yii\Debug\Collector\LogCollector; | ||
use Yiisoft\Yii\Debug\Collector\TimelineCollector; | ||
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase; | ||
|
||
final class TimelineCollectorTest extends AbstractCollectorTestCase | ||
{ | ||
/** | ||
* @param CollectorInterface|TimelineCollector $collector | ||
*/ | ||
protected function collectTestData(CollectorInterface $collector): void | ||
{ | ||
$collector->collect(new LogCollector($collector), '123'); | ||
$collector->collect(new LogCollector($collector), '345', 'context2', __FILE__ . ':' . __LINE__); | ||
} | ||
|
||
protected function getCollector(): CollectorInterface | ||
{ | ||
return new TimelineCollector(); | ||
} | ||
|
||
protected function checkCollectedData(array $data): void | ||
{ | ||
parent::checkCollectedData($data); | ||
|
||
$this->assertNotEmpty($data); | ||
$this->assertCount(2, $data); | ||
$this->assertCount(4, $data[0]); | ||
$this->assertSame(LogCollector::class, $data[0][2]); | ||
$this->assertSame('123', $data[0][1]); | ||
$this->assertSame([], $data[0][3]); | ||
|
||
$this->assertCount(4, $data[1]); | ||
$this->assertSame(LogCollector::class, $data[1][2]); | ||
$this->assertSame('345', $data[1][1]); | ||
$this->assertSame(['context2', __FILE__ . ':' . 29], $data[1][3]); | ||
} | ||
} |