@@ -15,6 +15,135 @@ public function testExpiredHTTPS() {
1515 parent ::testExpiredHTTPS ();
1616 }
1717
18+ public function testPoolMultiple () {
19+ $ requests = array (
20+ 'test1 ' => array (
21+ 'url ' => httpbin ('/get ' ),
22+ ),
23+ 'test2 ' => array (
24+ 'url ' => httpbin ('/get ' ),
25+ ),
26+ );
27+ $ responses = Requests::request_pool ($ requests , $ this ->getOptions ());
28+
29+ // test1
30+ $ this ->assertNotEmpty ($ responses ['test1 ' ]);
31+ $ this ->assertInstanceOf ('Requests_Response ' , $ responses ['test1 ' ]);
32+ $ this ->assertSame (200 , $ responses ['test1 ' ]->status_code );
33+
34+ $ result = json_decode ($ responses ['test1 ' ]->body , true );
35+ $ this ->assertSame (httpbin ('/get ' ), $ result ['url ' ]);
36+ $ this ->assertEmpty ($ result ['args ' ]);
37+
38+ // test2
39+ $ this ->assertNotEmpty ($ responses ['test2 ' ]);
40+ $ this ->assertInstanceOf ('Requests_Response ' , $ responses ['test2 ' ]);
41+ $ this ->assertSame (200 , $ responses ['test2 ' ]->status_code );
42+
43+ $ result = json_decode ($ responses ['test2 ' ]->body , true );
44+ $ this ->assertSame (httpbin ('/get ' ), $ result ['url ' ]);
45+ $ this ->assertEmpty ($ result ['args ' ]);
46+ }
47+
48+ public function testPoolWithDifferingMethods () {
49+ $ requests = array (
50+ 'get ' => array (
51+ 'url ' => httpbin ('/get ' ),
52+ ),
53+ 'post ' => array (
54+ 'url ' => httpbin ('/post ' ),
55+ 'type ' => Requests::POST ,
56+ 'data ' => 'test ' ,
57+ ),
58+ );
59+ $ responses = Requests::request_pool ($ requests , $ this ->getOptions ());
60+
61+ // get
62+ $ this ->assertSame (200 , $ responses ['get ' ]->status_code );
63+
64+ // post
65+ $ this ->assertSame (200 , $ responses ['post ' ]->status_code );
66+ $ result = json_decode ($ responses ['post ' ]->body , true );
67+ $ this ->assertSame ('test ' , $ result ['data ' ]);
68+ }
69+
70+ public function testPoolUsingCallbackAndFailure () {
71+ $ requests = array (
72+ 'success ' => array (
73+ 'url ' => httpbin ('/get ' ),
74+ ),
75+ 'timeout ' => array (
76+ 'url ' => httpbin ('/delay/10 ' ),
77+ 'options ' => array (
78+ 'timeout ' => 1 ,
79+ ),
80+ ),
81+ );
82+ $ this ->completed = array ();
83+ $ options = array (
84+ 'complete ' => array ($ this , 'completeCallback ' ),
85+ );
86+ $ responses = Requests::request_pool ($ requests , $ this ->getOptions ($ options ));
87+
88+ $ this ->assertSame ($ this ->completed , $ responses );
89+ $ this ->completed = array ();
90+ }
91+
92+ public function testPoolUsingCallback () {
93+ $ requests = array (
94+ 'get ' => array (
95+ 'url ' => httpbin ('/get ' ),
96+ ),
97+ 'post ' => array (
98+ 'url ' => httpbin ('/post ' ),
99+ 'type ' => Requests::POST ,
100+ 'data ' => 'test ' ,
101+ ),
102+ );
103+ $ this ->completed = array ();
104+ $ options = array (
105+ 'complete ' => array ($ this , 'completeCallback ' ),
106+ );
107+ $ responses = Requests::request_pool ($ requests , $ this ->getOptions ($ options ));
108+
109+ $ this ->assertSame ($ this ->completed , $ responses );
110+ $ this ->completed = array ();
111+ }
112+
113+ public function testPoolToFile () {
114+ $ requests = array (
115+ 'get ' => array (
116+ 'url ' => httpbin ('/get ' ),
117+ 'options ' => array (
118+ 'filename ' => tempnam (sys_get_temp_dir (), 'RLT ' ), // RequestsLibraryTest
119+ ),
120+ ),
121+ 'post ' => array (
122+ 'url ' => httpbin ('/post ' ),
123+ 'type ' => Requests::POST ,
124+ 'data ' => 'test ' ,
125+ 'options ' => array (
126+ 'filename ' => tempnam (sys_get_temp_dir (), 'RLT ' ), // RequestsLibraryTest
127+ ),
128+ ),
129+ );
130+ Requests::request_pool ($ requests , $ this ->getOptions ());
131+
132+ // GET request
133+ $ contents = file_get_contents ($ requests ['get ' ]['options ' ]['filename ' ]);
134+ $ result = json_decode ($ contents , true );
135+ $ this ->assertSame (httpbin ('/get ' ), $ result ['url ' ]);
136+ $ this ->assertEmpty ($ result ['args ' ]);
137+ unlink ($ requests ['get ' ]['options ' ]['filename ' ]);
138+
139+ // POST request
140+ $ contents = file_get_contents ($ requests ['post ' ]['options ' ]['filename ' ]);
141+ $ result = json_decode ($ contents , true );
142+ $ this ->assertSame (httpbin ('/post ' ), $ result ['url ' ]);
143+ $ this ->assertSame ('test ' , $ result ['data ' ]);
144+ unlink ($ requests ['post ' ]['options ' ]['filename ' ]);
145+ }
146+
18147 public function testRevokedHTTPS () {
19148 $ this ->expectException ('Requests_Exception ' );
20149 $ this ->expectExceptionMessage ('certificate subject name ' );
0 commit comments