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+ $ httpResponse = new HttpResponse (
52+ 418 ,
53+ [
54+ 'content-type ' => 'application/json '
55+ ],
56+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
57+ );
58+
59+ $ response = new Response ($ httpResponse );
60+ $ this ->assertEquals ('bar ' , $ response ['foo ' ]);
61+ }
62+
63+ public function testConstructResponseWith5xxHttpCode (): void
64+ {
65+ $ httpResponse = new HttpResponse (
66+ 510 ,
67+ [],
68+ Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
69+ );
70+
71+ $ response = new Response ($ httpResponse );
72+ $ this ->assertEquals ('{"foo":"bar"} ' , $ response ['content ' ]);
73+ }
74+ }
0 commit comments