PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.1
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.1
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 / CurlHandlerTest.php

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

87 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Test\Handler;
3
4 use GuzzleHttp\Exception\ConnectException;
5 use GuzzleHttp\Handler\CurlHandler;
6 use GuzzleHttp\Psr7;
7 use GuzzleHttp\Psr7\Request;
8 use GuzzleHttp\Psr7\Response;
9 use GuzzleHttp\Tests\Server;
10 use PHPUnit\Framework\TestCase;
11
12 /**
13 * @covers \GuzzleHttp\Handler\CurlHandler
14 */
15 class CurlHandlerTest extends TestCase
16 {
17 protected function getHandler($options = [])
18 {
19 return new CurlHandler($options);
20 }
21
22 /**
23 * @expectedException \GuzzleHttp\Exception\ConnectException
24 * @expectedExceptionMessage cURL
25 */
26 public function testCreatesCurlErrors()
27 {
28 $handler = new CurlHandler();
29 $request = new Request('GET', 'http://localhost:123');
30 $handler($request, ['timeout' => 0.001, 'connect_timeout' => 0.001])->wait();
31 }
32
33 public function testReusesHandles()
34 {
35 Server::flush();
36 $response = new response(200);
37 Server::enqueue([$response, $response]);
38 $a = new CurlHandler();
39 $request = new Request('GET', Server::$url);
40 self::assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
41 self::assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
42 }
43
44 public function testDoesSleep()
45 {
46 $response = new response(200);
47 Server::enqueue([$response]);
48 $a = new CurlHandler();
49 $request = new Request('GET', Server::$url);
50 $s = \GuzzleHttp\_current_time();
51 $a($request, ['delay' => 0.1])->wait();
52 self::assertGreaterThan(0.0001, \GuzzleHttp\_current_time() - $s);
53 }
54
55 public function testCreatesCurlErrorsWithContext()
56 {
57 $handler = new CurlHandler();
58 $request = new Request('GET', 'http://localhost:123');
59 $called = false;
60 $p = $handler($request, ['timeout' => 0.001, 'connect_timeout' => 0.001])
61 ->otherwise(function (ConnectException $e) use (&$called) {
62 $called = true;
63 self::assertArrayHasKey('errno', $e->getHandlerContext());
64 });
65 $p->wait();
66 self::assertTrue($called);
67 }
68
69 public function testUsesContentLengthWhenOverInMemorySize()
70 {
71 Server::flush();
72 Server::enqueue([new Response()]);
73 $stream = Psr7\stream_for(str_repeat('.', 1000000));
74 $handler = new CurlHandler();
75 $request = new Request(
76 'PUT',
77 Server::$url,
78 ['Content-Length' => 1000000],
79 $stream
80 );
81 $handler($request, [])->wait();
82 $received = Server::received()[0];
83 self::assertEquals(1000000, $received->getHeaderLine('Content-Length'));
84 self::assertFalse($received->hasHeader('Transfer-Encoding'));
85 }
86 }
87