From 29e4c1c821e263f689a3b39a9af866710737bd0e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 4 Sep 2024 22:09:21 +0200 Subject: [PATCH] c --- src/Collector/Collector.php | 2 -- src/Collector/Formatter.php | 2 -- src/Collector/ProfileClient.php | 4 +-- src/Collector/ProfileClientFactory.php | 2 -- src/Collector/ProfilePlugin.php | 2 -- src/Collector/StackPlugin.php | 2 -- tests/Unit/Collector/ProfileClientTest.php | 13 ++++++---- tests/Unit/Collector/ProfilePluginTest.php | 7 ++--- tests/Unit/Collector/StackPluginTest.php | 30 ++++++++++++++-------- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Collector/Collector.php b/src/Collector/Collector.php index 75e9dd9f..50a4aa8c 100644 --- a/src/Collector/Collector.php +++ b/src/Collector/Collector.php @@ -18,8 +18,6 @@ * @author Fabien Bourigault * * @internal - * - * @final */ final class Collector extends DataCollector { diff --git a/src/Collector/Formatter.php b/src/Collector/Formatter.php index 0928394a..f2032f24 100644 --- a/src/Collector/Formatter.php +++ b/src/Collector/Formatter.php @@ -18,8 +18,6 @@ * @author Fabien Bourigault * * @internal - * - * @final */ final class Formatter implements MessageFormatter { diff --git a/src/Collector/ProfileClient.php b/src/Collector/ProfileClient.php index 71bde28b..8ea52812 100644 --- a/src/Collector/ProfileClient.php +++ b/src/Collector/ProfileClient.php @@ -21,10 +21,8 @@ * @author Fabien Bourigault * * @internal - * - * @final */ -final class ProfileClient implements ClientInterace, HttpAsyncClient +final class ProfileClient implements ClientInterface, HttpAsyncClient { use VersionBridgeClient; diff --git a/src/Collector/ProfileClientFactory.php b/src/Collector/ProfileClientFactory.php index 7fcd1263..3715fd4d 100644 --- a/src/Collector/ProfileClientFactory.php +++ b/src/Collector/ProfileClientFactory.php @@ -16,8 +16,6 @@ * @author Fabien Bourigault * * @internal - * - * @final */ final class ProfileClientFactory implements ClientFactory { diff --git a/src/Collector/ProfilePlugin.php b/src/Collector/ProfilePlugin.php index 7cae523b..d6ed4a60 100644 --- a/src/Collector/ProfilePlugin.php +++ b/src/Collector/ProfilePlugin.php @@ -15,8 +15,6 @@ * @author Fabien Bourigault * * @internal - * - * @final */ final class ProfilePlugin implements Plugin { diff --git a/src/Collector/StackPlugin.php b/src/Collector/StackPlugin.php index c0460568..634aa299 100644 --- a/src/Collector/StackPlugin.php +++ b/src/Collector/StackPlugin.php @@ -15,8 +15,6 @@ * @author Fabien Bourigault * * @internal - * - * @final */ final class StackPlugin implements Plugin { diff --git a/tests/Unit/Collector/ProfileClientTest.php b/tests/Unit/Collector/ProfileClientTest.php index a7855027..0d73aeca 100644 --- a/tests/Unit/Collector/ProfileClientTest.php +++ b/tests/Unit/Collector/ProfileClientTest.php @@ -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; @@ -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); @@ -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') ; @@ -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()); } } diff --git a/tests/Unit/Collector/ProfilePluginTest.php b/tests/Unit/Collector/ProfilePluginTest.php index c83cdb01..5e392cac 100644 --- a/tests/Unit/Collector/ProfilePluginTest.php +++ b/tests/Unit/Collector/ProfilePluginTest.php @@ -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; @@ -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(); @@ -74,7 +75,7 @@ public function setUp(): void $this->subject = new ProfilePlugin( $this->plugin, $this->collector, - $this->formatter + $this->formatter, ); } @@ -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(); } } diff --git a/tests/Unit/Collector/StackPluginTest.php b/tests/Unit/Collector/StackPluginTest.php index cd828a24..50475d50 100644 --- a/tests/Unit/Collector/StackPluginTest.php +++ b/tests/Unit/Collector/StackPluginTest.php @@ -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; @@ -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(); @@ -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 @@ -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 @@ -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