PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.7
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.7
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / guzzlehttp / guzzle / tests / Handler / CurlMultiHandlerTest.php

CurlMultiHandlerTest.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.5.7, at vendor/guzzlehttp/guzzle/tests/Handler/CurlMultiHandlerTest.php

123 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Tests\Handler;
3
4 use GuzzleHttp\Handler\CurlMultiHandler;
5 use GuzzleHttp\Psr7\Request;
6 use GuzzleHttp\Psr7\Response;
7 use GuzzleHttp\Tests\Server;
8 use PHPUnit\Framework\TestCase;
9
10 class CurlMultiHandlerTest extends TestCase
11 {
12 public function setUp()
13 {
14 $_SERVER['curl_test'] = true;
15 unset($_SERVER['_curl_multi']);
16 }
17
18 public function tearDown()
19 {
20 unset($_SERVER['_curl_multi'], $_SERVER['curl_test']);
21 }
22
23 public function testCanAddCustomCurlOptions()
24 {
25 Server::flush();
26 Server::enqueue([new Response()]);
27 $a = new CurlMultiHandler(['options' => [
28 CURLMOPT_MAXCONNECTS => 5,
29 ]]);
30 $request = new Request('GET', Server::$url);
31 $a($request, []);
32 self::assertEquals(5, $_SERVER['_curl_multi'][CURLMOPT_MAXCONNECTS]);
33 }
34
35 public function testSendsRequest()
36 {
37 Server::enqueue([new Response()]);
38 $a = new CurlMultiHandler();
39 $request = new Request('GET', Server::$url);
40 $response = $a($request, [])->wait();
41 self::assertSame(200, $response->getStatusCode());
42 }
43
44 /**
45 * @expectedException \GuzzleHttp\Exception\ConnectException
46 * @expectedExceptionMessage cURL error
47 */
48 public function testCreatesExceptions()
49 {
50 $a = new CurlMultiHandler();
51 $a(new Request('GET', 'http://localhost:123'), [])->wait();
52 }
53
54 public function testCanSetSelectTimeout()
55 {
56 $a = new CurlMultiHandler(['select_timeout' => 2]);
57 self::assertEquals(2, self::readAttribute($a, 'selectTimeout'));
58 }
59
60 public function testCanCancel()
61 {
62 Server::flush();
63 $response = new Response(200);
64 Server::enqueue(array_fill_keys(range(0, 10), $response));
65 $a = new CurlMultiHandler();
66 $responses = [];
67 for ($i = 0; $i < 10; $i++) {
68 $response = $a(new Request('GET', Server::$url), []);
69 $response->cancel();
70 $responses[] = $response;
71 }
72
73 foreach ($responses as $r) {
74 self::assertSame('rejected', $response->getState());
75 }
76 }
77
78 public function testCannotCancelFinished()
79 {
80 Server::flush();
81 Server::enqueue([new Response(200)]);
82 $a = new CurlMultiHandler();
83 $response = $a(new Request('GET', Server::$url), []);
84 $response->wait();
85 $response->cancel();
86 self::assertSame('fulfilled', $response->getState());
87 }
88
89 public function testDelaysConcurrently()
90 {
91 Server::flush();
92 Server::enqueue([new Response()]);
93 $a = new CurlMultiHandler();
94 $expected = \GuzzleHttp\_current_time() + (100 / 1000);
95 $response = $a(new Request('GET', Server::$url), ['delay' => 100]);
96 $response->wait();
97 self::assertGreaterThanOrEqual($expected, \GuzzleHttp\_current_time());
98 }
99
100 public function testUsesTimeoutEnvironmentVariables()
101 {
102 $a = new CurlMultiHandler();
103
104 //default if no options are given and no environment variable is set
105 self::assertEquals(1, self::readAttribute($a, 'selectTimeout'));
106
107 putenv("GUZZLE_CURL_SELECT_TIMEOUT=3");
108 $a = new CurlMultiHandler();
109 $selectTimeout = getenv('GUZZLE_CURL_SELECT_TIMEOUT');
110 //Handler reads from the environment if no options are given
111 self::assertEquals($selectTimeout, self::readAttribute($a, 'selectTimeout'));
112 }
113
114 /**
115 * @expectedException \BadMethodCallException
116 */
117 public function throwsWhenAccessingInvalidProperty()
118 {
119 $h = new CurlMultiHandler();
120 $h->foo;
121 }
122 }
123