Skip to content

Commit 3ce84bc

Browse files
committed
c
1 parent dd01464 commit 3ce84bc

9 files changed

+44
-44
lines changed

src/Collector/Collector.php

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* @author Fabien Bourigault <[email protected]>
1919
*
2020
* @internal
21-
*
22-
* @final
2321
*/
2422
final class Collector extends DataCollector
2523
{

src/Collector/Formatter.php

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* @author Fabien Bourigault <[email protected]>
1919
*
2020
* @internal
21-
*
22-
* @final
2321
*/
2422
final class Formatter implements MessageFormatter
2523
{

src/Collector/ProfileClient.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
* @author Fabien Bourigault <[email protected]>
2222
*
2323
* @internal
24-
*
25-
* @final
2624
*/
27-
final class ProfileClient implements ClientInterace, HttpAsyncClient
25+
final class ProfileClient implements ClientInterface, HttpAsyncClient
2826
{
2927
use VersionBridgeClient;
3028

src/Collector/ProfileClientFactory.php

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* @author Fabien Bourigault <[email protected]>
1717
*
1818
* @internal
19-
*
20-
* @final
2119
*/
2220
final class ProfileClientFactory implements ClientFactory
2321
{

src/Collector/ProfilePlugin.php

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18-
*
19-
* @final
2018
*/
2119
final class ProfilePlugin implements Plugin
2220
{

src/Collector/StackPlugin.php

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18-
*
19-
* @final
2018
*/
2119
final class StackPlugin implements Plugin
2220
{

tests/Unit/Collector/ProfileClientTest.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Http\HttplugBundle\Collector\ProfileClient;
1414
use Http\HttplugBundle\Collector\Stack;
1515
use Http\Message\Formatter as MessageFormatter;
16+
use Http\Message\Formatter\SimpleFormatter;
1617
use Http\Promise\FulfilledPromise;
1718
use Http\Promise\Promise;
1819
use Http\Promise\RejectedPromise;
@@ -44,27 +45,26 @@ class ProfileClientTest extends TestCase
4445

4546
public function setUp(): void
4647
{
47-
$messageFormatter = $this->createMock(MessageFormatter::class);
48+
$messageFormatter = $this->createMock(SimpleFormatter::class);
4849
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
4950
$this->collector = new Collector();
5051
$stopwatch = $this->createMock(Stopwatch::class);
5152

52-
$this->activeStack = new Stack('default', 'FormattedRequest');
53-
$this->collector->activateStack($this->activeStack);
54-
53+
$activeStack = new Stack('default', 'FormattedRequest');
54+
$this->collector->activateStack($activeStack);
5555
$this->client = $this->getMockBuilder(CombinedClientInterface::class)->getMock();
5656
$uri = new Uri('https://example.com/target');
5757
$this->request = new Request('GET', $uri);
5858
$this->stopwatchEvent = $this->createMock(StopwatchEvent::class);
5959
$this->subject = new ProfileClient($this->client, $this->collector, $formatter, $stopwatch);
6060
$this->response = new Response();
61-
$this->exception = new \Exception();
61+
$exception = new \Exception('test');
6262
$this->fulfilledPromise = new FulfilledPromise($this->response);
63-
$this->rejectedPromise = new RejectedPromise($this->exception);
63+
$this->rejectedPromise = new RejectedPromise($exception);
6464

6565
$messageFormatter
66-
->method('formatResponse')
67-
->with($this->response)
66+
->method('formatResponseForRequest')
67+
->with($this->response, $this->request)
6868
->willReturn('FormattedResponse')
6969
;
7070

@@ -168,8 +168,10 @@ public function testOnRejected(): void
168168

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

171-
$this->assertEquals(42, $this->activeStack->getDuration());
172-
$this->assertEquals('FormattedResponse', $this->activeStack->getClientException());
171+
$activeStack = $this->collector->getActiveStack();
172+
$this->assertInstanceOf(Stack::class, $activeStack);
173+
$this->assertEquals(42, $activeStack->getDuration());
174+
$this->assertEquals('Unexpected exception of type "Exception": test', $activeStack->getClientException());
173175
}
174176
}
175177

tests/Unit/Collector/ProfilePluginTest.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Http\HttplugBundle\Collector\ProfilePlugin;
1414
use Http\HttplugBundle\Collector\Stack;
1515
use Http\Message\Formatter as MessageFormatter;
16+
use Http\Message\Formatter\SimpleFormatter;
1617
use Http\Promise\FulfilledPromise;
1718
use Http\Promise\Promise;
1819
use Http\Promise\RejectedPromise;
@@ -42,15 +43,15 @@ class ProfilePluginTest extends TestCase
4243
public function setUp(): void
4344
{
4445
$this->collector = new Collector();
45-
$messageFormatter = $this->createMock(MessageFormatter::class);
46-
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
46+
$messageFormatter = $this->createMock(SimpleFormatter::class);
47+
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
4748

48-
$this->plugin = $this->getMockBuilder(Plugin::class)->getMock();
49+
$this->plugin = $this->createMock(Plugin::class);
4950
$this->request = new Request('GET', '/');
5051
$this->response = new Response();
5152
$this->fulfilledPromise = new FulfilledPromise($this->response);
52-
$this->currentStack = new Stack('default', 'FormattedRequest');
53-
$this->collector->activateStack($this->currentStack);
53+
$currentStack = new Stack('default', 'FormattedRequest');
54+
$this->collector->activateStack($currentStack);
5455
$this->exception = new TransferException();
5556
$this->rejectedPromise = new RejectedPromise($this->exception);
5657

@@ -74,7 +75,7 @@ public function setUp(): void
7475
$this->subject = new ProfilePlugin(
7576
$this->plugin,
7677
$this->collector,
77-
$this->formatter
78+
$formatter,
7879
);
7980
}
8081

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

133-
$this->assertEquals($this->exception, $promise->wait());
134-
$profile = $this->currentStack->getProfiles()[0];
134+
$activeStack = $this->collector->getActiveStack();
135+
$this->assertCount(1, $activeStack->getProfiles());
135136
$this->expectException(TransferException::class);
136-
$profile->getResponse();
137+
$promise->wait();
137138
}
138139
}

tests/Unit/Collector/StackPluginTest.php

+21-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Http\HttplugBundle\Collector\Formatter;
1212
use Http\HttplugBundle\Collector\StackPlugin;
1313
use Http\Message\Formatter as MessageFormatter;
14+
use Http\Message\Formatter\SimpleFormatter;
1415
use Http\Promise\FulfilledPromise;
1516
use Http\Promise\RejectedPromise;
1617
use PHPUnit\Framework\Error\Warning;
@@ -48,8 +49,8 @@ class StackPluginTest extends TestCase
4849
public function setUp(): void
4950
{
5051
$this->collector = new Collector();
51-
$messageFormatter = $this->createMock(MessageFormatter::class);
52-
$this->formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
52+
$messageFormatter = $this->createMock(SimpleFormatter::class);
53+
$formatter = new Formatter($messageFormatter, $this->createMock(MessageFormatter::class));
5354
$this->request = new Request('GET', '/');
5455
$this->response = new Response();
5556
$this->exception = new HttpException('', $this->request, $this->response);
@@ -66,7 +67,7 @@ public function setUp(): void
6667
->willReturn('FormattedResponse')
6768
;
6869

69-
$this->subject = new StackPlugin($this->collector, $this->formatter, 'default');
70+
$this->subject = new StackPlugin($this->collector, $formatter, 'default');
7071
}
7172

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

79-
$stack = $this->collector->getActiveStack();
80-
$this->assertEquals('default', $stack->getClient());
81-
$this->assertEquals('FormattedRequest', $stack->getRequest());
80+
$this->assertNull($this->collector->getActiveStack());
81+
$stacks = $this->collector->getStacks();
82+
$this->assertCount(1, $stacks);
83+
$this->assertEquals('default', $stacks[0]->getClient());
84+
$this->assertEquals('FormattedRequest', $stacks[0]->getRequest());
8285
}
8386

8487
public function testOnFulfilled(): void
@@ -89,8 +92,10 @@ public function testOnFulfilled(): void
8992
});
9093

9194
$this->assertEquals($this->response, $promise->wait());
92-
$currentStack = $this->collector->getActiveStack();
93-
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
95+
$this->assertNull($this->collector->getActiveStack());
96+
$stacks = $this->collector->getStacks();
97+
$this->assertCount(1, $stacks);
98+
$this->assertEquals('FormattedResponse', $stacks[0]->getResponse());
9499
}
95100

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

103-
$this->assertEquals($this->exception, $promise->wait());
104-
$currentStack = $this->collector->getActiveStack();
105-
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
106-
$this->assertTrue($currentStack->isFailed());
108+
$this->assertNull($this->collector->getActiveStack());
109+
$stacks = $this->collector->getStacks();
110+
$this->assertCount(1, $stacks);
111+
$this->assertEquals('FormattedResponse', $stacks[0]->getResponse());
112+
$this->assertTrue($stacks[0]->isFailed());
113+
114+
$this->expectException(\Exception::class);
115+
$promise->wait();
107116
}
108117

109118
public function testOnException(): void

0 commit comments

Comments
 (0)