Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Sep 4, 2024
1 parent dd01464 commit 29e4c1c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 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
13 changes: 8 additions & 5 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,7 +45,7 @@ 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);
Expand All @@ -63,8 +64,8 @@ public function setUp(): void
$this->rejectedPromise = new RejectedPromise($this->exception);

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

Expand Down Expand Up @@ -168,8 +169,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
7 changes: 4 additions & 3 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,7 +43,7 @@ class ProfilePluginTest extends TestCase
public function setUp(): void
{
$this->collector = new Collector();
$messageFormatter = $this->createMock(MessageFormatter::class);
$messageFormatter = $this->createMock(SimpleFormatter::class);
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));

$this->plugin = $this->getMockBuilder(Plugin::class)->getMock();
Expand Down Expand Up @@ -74,7 +75,7 @@ public function setUp(): void
$this->subject = new ProfilePlugin(
$this->plugin,
$this->collector,
$this->formatter
$this->formatter,
);
}

Expand Down Expand Up @@ -131,8 +132,8 @@ public function testOnRejected(): void
});

$this->assertEquals($this->exception, $promise->wait());
$profile = $this->currentStack->getProfiles()[0];
$this->expectException(TransferException::class);
$profile = $this->currentStack->getProfiles()[0];
$profile->getResponse();
}
}
30 changes: 19 additions & 11 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,7 +49,7 @@ class StackPluginTest extends TestCase
public function setUp(): void
{
$this->collector = new Collector();
$messageFormatter = $this->createMock(MessageFormatter::class);
$messageFormatter = $this->createMock(SimpleFormatter::class);
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
$this->request = new Request('GET', '/');
$this->response = new Response();
Expand Down Expand Up @@ -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 @@ -88,9 +91,10 @@ public function testOnFulfilled(): void
$promise = $this->subject->handleRequest($this->request, $next, function (): 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 +104,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 29e4c1c

Please sign in to comment.