Skip to content

Commit

Permalink
Cover HttpClientCollectorProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Oct 13, 2023
1 parent e93c5a8 commit e09acbe
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/Unit/Collector/HttpClientInterfaceProxyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use Yiisoft\Yii\Debug\Collector\HttpClientCollector;
use Yiisoft\Yii\Debug\Collector\HttpClientInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;

final class HttpClientInterfaceProxyTest extends TestCase
{
public function testSendRequest()
{
$request = new Request('GET', 'http://example.com');
$response = new Response(200, [], 'test');

$client = $this->createMock(ClientInterface::class);
$client->expects($this->once())
->method('sendRequest')
->with($request)
->willReturn($response);
$collector = new HttpClientCollector(new TimelineCollector());
$collector->startup();

$proxy = new HttpClientInterfaceProxy($client, $collector);

$newResponse = $proxy->sendRequest($request);

$this->assertSame($newResponse, $response);
$this->assertCount(1, $collector->getCollected());
}
}

0 comments on commit e09acbe

Please sign in to comment.