@@ -167,7 +167,7 @@ public function testCookies() {
167
167
public function testError () {
168
168
$ test = new Test ();
169
169
$ test ->curl ->setOpt (CURLOPT_CONNECTTIMEOUT_MS , 2000 );
170
- $ test ->curl ->get (' http://1.2.3.4/ ' );
170
+ $ test ->curl ->get (Test:: ERROR_URL );
171
171
$ this ->assertTrue ($ test ->curl ->error === TRUE );
172
172
$ this ->assertTrue ($ test ->curl ->curl_error === TRUE );
173
173
$ this ->assertTrue ($ test ->curl ->curl_error_code === CURLE_OPERATION_TIMEOUTED );
@@ -297,4 +297,43 @@ public function testParallelRequests() {
297
297
$ this ->assertTrue (substr ($ curl ->curls ['1 ' ]->response , - $ len ) === '/b/?foo=bar ' );
298
298
$ this ->assertTrue (substr ($ curl ->curls ['2 ' ]->response , - $ len ) === '/c/?foo=bar ' );
299
299
}
300
+
301
+ public function testSuccessCallback () {
302
+ $ success_called = FALSE ;
303
+ $ error_called = FALSE ;
304
+ $ complete_called = FALSE ;
305
+
306
+ $ curl = new Curl ();
307
+ $ curl ->setHeader ('X-DEBUG-TEST ' , 'get ' );
308
+ $ curl ->setOpt (CURLOPT_SSL_VERIFYPEER , FALSE );
309
+ $ curl ->setOpt (CURLOPT_SSL_VERIFYHOST , FALSE );
310
+
311
+ $ curl ->success (function ($ instance ) use (&$ success_called , &$ error_called , &$ complete_called ) {
312
+ PHPUnit_Framework_Assert::assertInstanceOf ('Curl ' , $ instance );
313
+ PHPUnit_Framework_Assert::assertFalse ($ success_called );
314
+ PHPUnit_Framework_Assert::assertFalse ($ error_called );
315
+ PHPUnit_Framework_Assert::assertFalse ($ complete_called );
316
+ $ success_called = TRUE ;
317
+ });
318
+ $ curl ->error (function ($ instance ) use (&$ success_called , &$ error_called , &$ complete_called , &$ curl ) {
319
+ PHPUnit_Framework_Assert::assertInstanceOf ('Curl ' , $ instance );
320
+ PHPUnit_Framework_Assert::assertFalse ($ success_called );
321
+ PHPUnit_Framework_Assert::assertFalse ($ error_called );
322
+ PHPUnit_Framework_Assert::assertFalse ($ complete_called );
323
+ $ error_called = TRUE ;
324
+ });
325
+ $ curl ->complete (function ($ instance ) use (&$ success_called , &$ error_called , &$ complete_called ) {
326
+ PHPUnit_Framework_Assert::assertInstanceOf ('Curl ' , $ instance );
327
+ PHPUnit_Framework_Assert::assertTrue ($ success_called );
328
+ PHPUnit_Framework_Assert::assertFalse ($ error_called );
329
+ PHPUnit_Framework_Assert::assertFalse ($ complete_called );
330
+ $ complete_called = TRUE ;
331
+ });
332
+
333
+ $ curl ->get (Test::TEST_URL );
334
+
335
+ $ this ->assertTrue ($ success_called );
336
+ $ this ->assertFalse ($ error_called );
337
+ $ this ->assertTrue ($ complete_called );
338
+ }
300
339
}
0 commit comments