diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 92e2fa06..a27a5a7c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -285,6 +285,16 @@ parameters: count: 1 path: src/Tracing/HttpClient/TraceableHttpClientForV6.php + - + message: "#^Parameter \\#1 $responses of method Sentry\\\\SentryBundle\\\\Tracing\\\\HttpClient\\\\AbstractTraceableHttpClient::stream\\(\\) expects iterable<\\(int\\|string\\), Symfony\\\\Contracts\\\\HttpClient\\\\ResponseInterface>|Symfony\\\\Contracts\\\\HttpClient\\\\ResponseInterface, stdClass given\\.$#" + count: 1 + path: tests/Tracing/HttpClient/TraceableHttpClientTest.php + + - + message: "#^Parameter \\#2 \\$responses of static method Sentry\\\\SentryBundle\\\\Tracing\\\\HttpClient\\\\AbstractTraceableResponse::stream\\(\\) expects iterable, array given\\.$#" + count: 1 + path: tests/Tracing/HttpClient/TraceableResponseTest.php + - message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#" count: 1 diff --git a/tests/Tracing/HttpClient/TraceableHttpClientTest.php b/tests/Tracing/HttpClient/TraceableHttpClientTest.php index 069d8682..9a1551b3 100644 --- a/tests/Tracing/HttpClient/TraceableHttpClientTest.php +++ b/tests/Tracing/HttpClient/TraceableHttpClientTest.php @@ -142,6 +142,13 @@ public function testStream(): void $this->assertSame(1, $loopIndex); } + public function testStreamShouldThrowOnWrongParameterType(): void + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('"Sentry\SentryBundle\Tracing\HttpClient\AbstractTraceableHttpClient::stream()" expects parameter 1 to be an iterable of TraceableResponse objects, "stdClass" given.'); + $this->httpClient->stream(new \stdClass()); + } + public function testSetLoggerShouldBeForwardedToDecoratedInstance(): void { $logger = new NullLogger(); diff --git a/tests/Tracing/HttpClient/TraceableResponseTest.php b/tests/Tracing/HttpClient/TraceableResponseTest.php index 1f2b213a..69a80612 100644 --- a/tests/Tracing/HttpClient/TraceableResponseTest.php +++ b/tests/Tracing/HttpClient/TraceableResponseTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Contracts\HttpClient\HttpClientInterface; +use Symfony\Contracts\HttpClient\ResponseInterface; final class TraceableResponseTest extends TestCase { @@ -130,4 +131,13 @@ public function testToStream(): void $this->assertSame('foobar', stream_get_contents($response->toStream())); } + + public function testStreamWithWrongObjectsShouldThrow(): void + { + $httpClient = new MockHttpClient(new MockResponse('foobar')); + $response = $this->createMock(ResponseInterface::class); + + $this->expectException(\TypeError::class); + iterator_to_array(TraceableResponse::stream($httpClient, [$response], null)); + } }