Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Sep 5, 2024
1 parent dd01464 commit 3ce84bc
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/Collector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class Collector extends DataCollector
{
Expand Down
2 changes: 0 additions & 2 deletions src/Collector/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class Formatter implements MessageFormatter
{
Expand Down
4 changes: 1 addition & 3 deletions src/Collector/ProfileClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class ProfileClient implements ClientInterace, HttpAsyncClient
final class ProfileClient implements ClientInterface, HttpAsyncClient
{
use VersionBridgeClient;

Expand Down
2 changes: 0 additions & 2 deletions src/Collector/ProfileClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class ProfileClientFactory implements ClientFactory
{
Expand Down
2 changes: 0 additions & 2 deletions src/Collector/ProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class ProfilePlugin implements Plugin
{
Expand Down
2 changes: 0 additions & 2 deletions src/Collector/StackPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* @author Fabien Bourigault <[email protected]>
*
* @internal
*
* @final
*/
final class StackPlugin implements Plugin
{
Expand Down
22 changes: 12 additions & 10 deletions tests/Unit/Collector/ProfileClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Http\HttplugBundle\Collector\ProfileClient;
use Http\HttplugBundle\Collector\Stack;
use Http\Message\Formatter as MessageFormatter;
use Http\Message\Formatter\SimpleFormatter;
use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Http\Promise\RejectedPromise;
Expand Down Expand Up @@ -44,27 +45,26 @@ class ProfileClientTest extends TestCase

public function setUp(): void
{
$messageFormatter = $this->createMock(MessageFormatter::class);
$messageFormatter = $this->createMock(SimpleFormatter::class);
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
$this->collector = new Collector();
$stopwatch = $this->createMock(Stopwatch::class);

$this->activeStack = new Stack('default', 'FormattedRequest');
$this->collector->activateStack($this->activeStack);

$activeStack = new Stack('default', 'FormattedRequest');
$this->collector->activateStack($activeStack);
$this->client = $this->getMockBuilder(CombinedClientInterface::class)->getMock();
$uri = new Uri('https://example.com/target');
$this->request = new Request('GET', $uri);
$this->stopwatchEvent = $this->createMock(StopwatchEvent::class);
$this->subject = new ProfileClient($this->client, $this->collector, $formatter, $stopwatch);
$this->response = new Response();
$this->exception = new \Exception();
$exception = new \Exception('test');
$this->fulfilledPromise = new FulfilledPromise($this->response);
$this->rejectedPromise = new RejectedPromise($this->exception);
$this->rejectedPromise = new RejectedPromise($exception);

$messageFormatter
->method('formatResponse')
->with($this->response)
->method('formatResponseForRequest')
->with($this->response, $this->request)
->willReturn('FormattedResponse')
;

Expand Down Expand Up @@ -168,8 +168,10 @@ public function testOnRejected(): void

$this->subject->sendAsyncRequest($this->request);

$this->assertEquals(42, $this->activeStack->getDuration());
$this->assertEquals('FormattedResponse', $this->activeStack->getClientException());
$activeStack = $this->collector->getActiveStack();
$this->assertInstanceOf(Stack::class, $activeStack);
$this->assertEquals(42, $activeStack->getDuration());
$this->assertEquals('Unexpected exception of type "Exception": test', $activeStack->getClientException());
}
}

Expand Down
19 changes: 10 additions & 9 deletions tests/Unit/Collector/ProfilePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Http\HttplugBundle\Collector\ProfilePlugin;
use Http\HttplugBundle\Collector\Stack;
use Http\Message\Formatter as MessageFormatter;
use Http\Message\Formatter\SimpleFormatter;
use Http\Promise\FulfilledPromise;
use Http\Promise\Promise;
use Http\Promise\RejectedPromise;
Expand Down Expand Up @@ -42,15 +43,15 @@ class ProfilePluginTest extends TestCase
public function setUp(): void
{
$this->collector = new Collector();
$messageFormatter = $this->createMock(MessageFormatter::class);
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
$messageFormatter = $this->createMock(SimpleFormatter::class);
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));

$this->plugin = $this->getMockBuilder(Plugin::class)->getMock();
$this->plugin = $this->createMock(Plugin::class);
$this->request = new Request('GET', '/');
$this->response = new Response();
$this->fulfilledPromise = new FulfilledPromise($this->response);
$this->currentStack = new Stack('default', 'FormattedRequest');
$this->collector->activateStack($this->currentStack);
$currentStack = new Stack('default', 'FormattedRequest');
$this->collector->activateStack($currentStack);
$this->exception = new TransferException();
$this->rejectedPromise = new RejectedPromise($this->exception);

Expand All @@ -74,7 +75,7 @@ public function setUp(): void
$this->subject = new ProfilePlugin(
$this->plugin,
$this->collector,
$this->formatter
$formatter,
);
}

Expand Down Expand Up @@ -130,9 +131,9 @@ public function testOnRejected(): void
$promise = $this->subject->handleRequest($this->request, fn () => $this->rejectedPromise, function (): void {
});

$this->assertEquals($this->exception, $promise->wait());
$profile = $this->currentStack->getProfiles()[0];
$activeStack = $this->collector->getActiveStack();
$this->assertCount(1, $activeStack->getProfiles());
$this->expectException(TransferException::class);
$profile->getResponse();
$promise->wait();
}
}
33 changes: 21 additions & 12 deletions tests/Unit/Collector/StackPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Http\HttplugBundle\Collector\Formatter;
use Http\HttplugBundle\Collector\StackPlugin;
use Http\Message\Formatter as MessageFormatter;
use Http\Message\Formatter\SimpleFormatter;
use Http\Promise\FulfilledPromise;
use Http\Promise\RejectedPromise;
use PHPUnit\Framework\Error\Warning;
Expand Down Expand Up @@ -48,8 +49,8 @@ class StackPluginTest extends TestCase
public function setUp(): void
{
$this->collector = new Collector();
$messageFormatter = $this->createMock(MessageFormatter::class);
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
$messageFormatter = $this->createMock(SimpleFormatter::class);
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
$this->request = new Request('GET', '/');
$this->response = new Response();
$this->exception = new HttpException('', $this->request, $this->response);
Expand All @@ -66,7 +67,7 @@ public function setUp(): void
->willReturn('FormattedResponse')
;

$this->subject = new StackPlugin($this->collector, $this->formatter, 'default');
$this->subject = new StackPlugin($this->collector, $formatter, 'default');
}

public function testStackIsInitialized(): void
Expand All @@ -76,9 +77,11 @@ public function testStackIsInitialized(): void
$this->subject->handleRequest($this->request, $next, function (): void {
});

$stack = $this->collector->getActiveStack();
$this->assertEquals('default', $stack->getClient());
$this->assertEquals('FormattedRequest', $stack->getRequest());
$this->assertNull($this->collector->getActiveStack());
$stacks = $this->collector->getStacks();
$this->assertCount(1, $stacks);
$this->assertEquals('default', $stacks[0]->getClient());
$this->assertEquals('FormattedRequest', $stacks[0]->getRequest());
}

public function testOnFulfilled(): void
Expand All @@ -89,8 +92,10 @@ public function testOnFulfilled(): void
});

$this->assertEquals($this->response, $promise->wait());
$currentStack = $this->collector->getActiveStack();
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
$this->assertNull($this->collector->getActiveStack());
$stacks = $this->collector->getStacks();
$this->assertCount(1, $stacks);
$this->assertEquals('FormattedResponse', $stacks[0]->getResponse());
}

public function testOnRejected(): void
Expand All @@ -100,10 +105,14 @@ public function testOnRejected(): void
$promise = $this->subject->handleRequest($this->request, $next, function (): void {
});

$this->assertEquals($this->exception, $promise->wait());
$currentStack = $this->collector->getActiveStack();
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
$this->assertTrue($currentStack->isFailed());
$this->assertNull($this->collector->getActiveStack());
$stacks = $this->collector->getStacks();
$this->assertCount(1, $stacks);
$this->assertEquals('FormattedResponse', $stacks[0]->getResponse());
$this->assertTrue($stacks[0]->isFailed());

$this->expectException(\Exception::class);
$promise->wait();
}

public function testOnException(): void
Expand Down

0 comments on commit 3ce84bc

Please sign in to comment.