1010use Thenativeweb \Eventsourcingdb \Stream \CurlMultiHandler ;
1111use Thenativeweb \Eventsourcingdb \Stream \Queue ;
1212use Thenativeweb \Eventsourcingdb \Stream \Request ;
13+ use Thenativeweb \Eventsourcingdb \Tests \ClientTestTrait ;
1314
1415final class CurlMultiHandlerTest extends TestCase
1516{
17+ use ClientTestTrait;
18+
1619 public function getPropertyValue (object $ object , string $ propertyName ): mixed
1720 {
1821 $ reflectionClass = new ReflectionClass ($ object );
@@ -21,6 +24,11 @@ public function getPropertyValue(object $object, string $propertyName): mixed
2124 return $ reflectionProperty ->getValue ($ object );
2225 }
2326
27+ public function removeLineBrakes (string $ line ): string
28+ {
29+ return preg_replace ('/\r\n|\r|\n/ ' , '' , $ line );
30+ }
31+
2432 public function testAbortInWithPositiveValue (): void
2533 {
2634 $ curlMultiHandler = new CurlMultiHandler ();
@@ -78,6 +86,41 @@ public function testExecuteThrowsIfHandleMissing(): void
7886 $ curlMultiHandler ->execute ();
7987 }
8088
89+ public function testExecuteThrowsIfHostNotExists (): void
90+ {
91+ $ this ->expectException (RuntimeException::class);
92+ $ this ->expectExceptionMessageMatches ("#Internal HttpClient: cURL handle execution failed with error: Failed to connect to [^ ]+ port 1234 after \d+ ms: Couldn't connect to server# " );
93+
94+ $ host = $ this ->container ->getHost ();
95+ $ baseUrl = "http:// {$ host }:1234 " ;
96+
97+ $ request = new Request (
98+ 'GET ' ,
99+ $ baseUrl ,
100+ );
101+ $ curlMultiHandler = new CurlMultiHandler ();
102+ $ curlMultiHandler ->addHandle ($ request );
103+ $ curlMultiHandler ->execute ();
104+ }
105+
106+ public function testExecuteSendsRequestAndParsesHttpHeadersCorrectly (): void
107+ {
108+ $ request = new Request (
109+ 'GET ' ,
110+ $ this ->container ->getBaseUrl () . '/api/v1/ping ' ,
111+ );
112+ $ curlMultiHandler = new CurlMultiHandler ();
113+ $ curlMultiHandler ->addHandle ($ request );
114+ $ curlMultiHandler ->execute ();
115+
116+ $ headerQueue = $ curlMultiHandler ->getHeaderQueue ();
117+
118+ $ this ->assertGreaterThanOrEqual (8 , $ headerQueue ->getIterator ()->count ());
119+ $ this ->assertSame ('HTTP/1.1 200 OK ' , $ this ->removeLineBrakes ($ headerQueue ->read ()));
120+ $ this ->assertSame ('Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate ' , $ this ->removeLineBrakes ($ headerQueue ->read ()));
121+ $ this ->assertSame ('Content-Type: application/json ' , $ this ->removeLineBrakes ($ headerQueue ->read ()));
122+ }
123+
81124 public function testContentIteratorThrowsIfMultiHandleMissing (): void
82125 {
83126 $ this ->expectException (RuntimeException::class);
0 commit comments