Skip to content

Commit 71ba653

Browse files
committed
add error conditions tests for stream methods
1 parent dcea7b5 commit 71ba653

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ parameters:
285285
count: 1
286286
path: src/Tracing/HttpClient/TraceableHttpClientForV6.php
287287

288+
-
289+
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\\.$#"
290+
count: 1
291+
path: tests/Tracing/HttpClient/TraceableHttpClientTest.php
292+
293+
-
294+
message: "#^Parameter \\#2 \\$responses of static method Sentry\\\\SentryBundle\\\\Tracing\\\\HttpClient\\\\AbstractTraceableResponse::stream\\(\\) expects iterable<Sentry\\\\SentryBundle\\\\Tracing\\\\HttpClient\\\\AbstractTraceableResponse>, array<int, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Contracts\\\\HttpClient\\\\ResponseInterface> given\\.$#"
295+
count: 1
296+
path: tests/Tracing/HttpClient/TraceableResponseTest.php
297+
288298
-
289299
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
290300
count: 1

tests/Tracing/HttpClient/TraceableHttpClientTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public function testStream(): void
142142
$this->assertSame(1, $loopIndex);
143143
}
144144

145+
public function testStreamShouldThrowOnWrongParameterType(): void
146+
{
147+
$this->expectException(\TypeError::class);
148+
$this->expectExceptionMessage('"Sentry\SentryBundle\Tracing\HttpClient\AbstractTraceableHttpClient::stream()" expects parameter 1 to be an iterable of TraceableResponse objects, "stdClass" given.');
149+
$this->httpClient->stream(new \stdClass());
150+
}
151+
145152
public function testSetLoggerShouldBeForwardedToDecoratedInstance(): void
146153
{
147154
$logger = new NullLogger();

tests/Tracing/HttpClient/TraceableResponseTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpClient\MockHttpClient;
1616
use Symfony\Component\HttpClient\Response\MockResponse;
1717
use Symfony\Contracts\HttpClient\HttpClientInterface;
18+
use Symfony\Contracts\HttpClient\ResponseInterface;
1819

1920
final class TraceableResponseTest extends TestCase
2021
{
@@ -130,4 +131,13 @@ public function testToStream(): void
130131

131132
$this->assertSame('foobar', stream_get_contents($response->toStream()));
132133
}
134+
135+
public function testStreamWithWrongObjectsShouldThrow(): void
136+
{
137+
$httpClient = new MockHttpClient(new MockResponse('foobar'));
138+
$response = $this->createMock(ResponseInterface::class);
139+
140+
$this->expectException(\TypeError::class);
141+
iterator_to_array(TraceableResponse::stream($httpClient, [$response], null));
142+
}
133143
}

0 commit comments

Comments
 (0)