Skip to content

Commit

Permalink
add error conditions tests for stream methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Jul 12, 2022
1 parent dcea7b5 commit 71ba653
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -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<Sentry\\\\SentryBundle\\\\Tracing\\\\HttpClient\\\\AbstractTraceableResponse>, array<int, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Contracts\\\\HttpClient\\\\ResponseInterface> given\\.$#"
count: 1
path: tests/Tracing/HttpClient/TraceableResponseTest.php

-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
count: 1
Expand Down
7 changes: 7 additions & 0 deletions tests/Tracing/HttpClient/TraceableHttpClientTest.php
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions tests/Tracing/HttpClient/TraceableResponseTest.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 71ba653

Please sign in to comment.