From 181a5b5a1ff5d16d1df057f9069048b2d79df366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Tobias=20de=20Freitas=20Neto?= Date: Fri, 25 Aug 2023 17:39:37 -0400 Subject: [PATCH] =?UTF-8?q?Adicionando=20teste=20unit=C3=A1rio=20para=20Gu?= =?UTF-8?q?zzleLoggingMiddleware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/GuzzleLoggingMiddlewareTest.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Unit/GuzzleLoggingMiddlewareTest.php diff --git a/tests/Unit/GuzzleLoggingMiddlewareTest.php b/tests/Unit/GuzzleLoggingMiddlewareTest.php new file mode 100644 index 0000000..2cfdecf --- /dev/null +++ b/tests/Unit/GuzzleLoggingMiddlewareTest.php @@ -0,0 +1,55 @@ +getMockBuilder(GuzzleEventCaptured::class) + ->disableOriginalConstructor() + ->getMock(); + + + $middleware = new GuzzleLoggingMiddleware(); + $handlerStack = \GuzzleHttp\HandlerStack::create(new MockHandler([ + function ($request, $options) use ($eventMock) { + // Assert that the event is triggered with the correct arguments + $this->assertInstanceOf(RequestInterface::class, $request); + $this->assertIsArray($options); + + // Simulate the event trigger + event(new GuzzleEventCaptured($request, $options)); + + return new Response(200); + } + ])); + $handlerStack->push($middleware); + + $client = new Client(['handler' => $handlerStack]); + + $response = $client->request('GET', 'https://example.com'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + } +} \ No newline at end of file