1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Tests \Unit ;
8+
9+ use GuzzleHttp \Psr7 \Response as HttpResponse ;
10+ use GuzzleHttp \Psr7 \Utils ;
11+ use PHPUnit \Framework \TestCase ;
12+ use Psr \Http \Message \ResponseInterface ;
13+ use Qdrant \Exception \InvalidArgumentException ;
14+ use Qdrant \Exception \ServerException ;
15+ use Qdrant \Response ;
16+
17+ class ResponseTest extends TestCase
18+ {
19+ public function testConstructResponse (): void
20+ {
21+ $ httpResponse = new HttpResponse (
22+ 200 ,
23+ [
24+ 'content-type ' => 'application/json '
25+ ],
26+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
27+ );
28+
29+ $ response = new Response ($ httpResponse );
30+
31+ $ this ->assertEquals ('bar ' , $ response ['foo ' ]);
32+ }
33+
34+ public function testConstructResponse2 (): void
35+ {
36+ $ httpResponse = new HttpResponse (
37+ 200 ,
38+ [
39+ 'content-type ' => 'text/html '
40+ ],
41+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
42+ );
43+
44+ $ response = new Response ($ httpResponse );
45+
46+ $ this ->assertEquals ('{"foo":"bar"} ' , $ response ['content ' ]);
47+ }
48+
49+ public function testConstructResponseWith4xxHttpCode (): void
50+ {
51+ $ this ->expectException (InvalidArgumentException::class);
52+ $ this ->expectExceptionMessage ('Invalid argument exception ' );
53+ $ this ->expectExceptionCode (418 );
54+ $ httpResponse = new HttpResponse (
55+ 418 ,
56+ [
57+ 'content-type ' => 'application/json '
58+ ],
59+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
60+ );
61+
62+ new Response ($ httpResponse );
63+ }
64+
65+ public function testConstructResponseWith5xxHttpCode (): void
66+ {
67+ $ this ->expectException (ServerException::class);
68+ $ this ->expectExceptionMessage ('Server Exception ' );
69+ $ this ->expectExceptionCode (510 );
70+ $ httpResponse = new HttpResponse (
71+ 510 ,
72+ [],
73+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
74+ );
75+
76+ new Response ($ httpResponse );
77+ }
78+ }
0 commit comments