1+ <?php
2+
3+ namespace Curl \Tests ;
4+
5+ use Curl \Client ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ class HttpBinTest extends TestCase
9+ {
10+ public function test_get ()
11+ {
12+ $ client = new Client ();
13+ $ response = $ client ->request ('GET ' , 'http://httpbin.org/get ' );
14+ $ this ->assertEquals (200 , $ response ->status );
15+ }
16+
17+ public function test_form_post ()
18+ {
19+ $ client = new Client ();
20+
21+ $ form_data = array (
22+ 'username ' => 'test ' ,
23+ 'password ' => 'pass '
24+ );
25+
26+ $ response = $ client ->request ('POST ' , 'http://httpbin.org/post ' , $ form_data );
27+
28+ $ this ->assertEquals (200 , $ response ->status );
29+
30+ $ json = json_decode ($ response ->body , true );
31+
32+ $ this ->assertEquals ($ form_data , $ json ['form ' ]);
33+ }
34+
35+ public function test_raw_post ()
36+ {
37+ $ client = new Client ();
38+
39+ $ post_data = "I_AM_STRING " ;
40+
41+ $ response = $ client ->request ('POST ' , 'http://httpbin.org/post ' , $ post_data , [
42+ 'Content-Type ' => 'text/plain '
43+ ]);
44+
45+ $ json = json_decode ($ response ->body , true );
46+
47+ $ this ->assertEquals ($ post_data , $ json ['data ' ]);
48+ }
49+
50+ public function test_status_code ()
51+ {
52+ $ client = new Client ();
53+ $ response = $ client ->request ('GET ' , 'http://httpbin.org/status/400 ' );
54+
55+ $ this ->assertEquals (400 , $ response ->status );
56+ }
57+
58+ public function test_redirect ()
59+ {
60+ $ client = new Client ();
61+
62+ $ redirect_to = "https://azenv.net/ " ;
63+
64+ $ response = $ client ->request ('GET ' , 'https://httpbin.org/redirect-to ' , [
65+ 'url ' => $ redirect_to
66+ ]);
67+
68+ $ this ->assertEquals (200 , $ response ->status );
69+ $ this ->assertEquals ($ redirect_to , $ response ->info ['url ' ]);
70+ }
71+
72+ public function test_redirect_nofollow ()
73+ {
74+ $ client = new Client ();
75+
76+ $ redirect_to = "https://azenv.net/ " ;
77+
78+ $ response = $ client ->request ('GET ' , 'https://httpbin.org/redirect-to ' , [
79+ 'url ' => $ redirect_to
80+ ], [], [
81+ CURLOPT_FOLLOWLOCATION => 0
82+ ]);
83+
84+ $ this ->assertEquals (302 , $ response ->status );
85+ }
86+ }
0 commit comments