@@ 53-94 (lines=42) @@ | ||
50 | $this->curlClient = new FacebookCurlHttpClient($this->curlMock); |
|
51 | } |
|
52 | ||
53 | public function testCanOpenGetCurlConnection() |
|
54 | { |
|
55 | $this->curlMock |
|
56 | ->shouldReceive('init') |
|
57 | ->once() |
|
58 | ->andReturn(null); |
|
59 | $this->curlMock |
|
60 | ->shouldReceive('setoptArray') |
|
61 | ->with(m::on(function ($arg) { |
|
62 | ||
63 | // array_diff() will sometimes trigger error on child-arrays |
|
64 | if (['X-Foo-Header: X-Bar'] !== $arg[CURLOPT_HTTPHEADER]) { |
|
65 | return false; |
|
66 | } |
|
67 | unset($arg[CURLOPT_HTTPHEADER]); |
|
68 | ||
69 | $caInfo = array_diff($arg, [ |
|
70 | CURLOPT_CUSTOMREQUEST => 'GET', |
|
71 | CURLOPT_URL => 'http://foo.com', |
|
72 | CURLOPT_CONNECTTIMEOUT => 10, |
|
73 | CURLOPT_TIMEOUT => 123, |
|
74 | CURLOPT_RETURNTRANSFER => true, |
|
75 | CURLOPT_HEADER => true, |
|
76 | CURLOPT_SSL_VERIFYHOST => 2, |
|
77 | CURLOPT_SSL_VERIFYPEER => true, |
|
78 | ]); |
|
79 | ||
80 | if (count($caInfo) !== 1) { |
|
81 | return false; |
|
82 | } |
|
83 | ||
84 | if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) { |
|
85 | return false; |
|
86 | } |
|
87 | ||
88 | return true; |
|
89 | })) |
|
90 | ->once() |
|
91 | ->andReturn(null); |
|
92 | ||
93 | $this->curlClient->openConnection('http://foo.com', 'GET', 'foo_body', ['X-Foo-Header' => 'X-Bar'], 123); |
|
94 | } |
|
95 | ||
96 | public function testCanOpenCurlConnectionWithPostBody() |
|
97 | { |
|
@@ 96-138 (lines=43) @@ | ||
93 | $this->curlClient->openConnection('http://foo.com', 'GET', 'foo_body', ['X-Foo-Header' => 'X-Bar'], 123); |
|
94 | } |
|
95 | ||
96 | public function testCanOpenCurlConnectionWithPostBody() |
|
97 | { |
|
98 | $this->curlMock |
|
99 | ->shouldReceive('init') |
|
100 | ->once() |
|
101 | ->andReturn(null); |
|
102 | $this->curlMock |
|
103 | ->shouldReceive('setoptArray') |
|
104 | ->with(m::on(function ($arg) { |
|
105 | ||
106 | // array_diff() will sometimes trigger error on child-arrays |
|
107 | if ([] !== $arg[CURLOPT_HTTPHEADER]) { |
|
108 | return false; |
|
109 | } |
|
110 | unset($arg[CURLOPT_HTTPHEADER]); |
|
111 | ||
112 | $caInfo = array_diff($arg, [ |
|
113 | CURLOPT_CUSTOMREQUEST => 'POST', |
|
114 | CURLOPT_URL => 'http://bar.com', |
|
115 | CURLOPT_CONNECTTIMEOUT => 10, |
|
116 | CURLOPT_TIMEOUT => 60, |
|
117 | CURLOPT_RETURNTRANSFER => true, |
|
118 | CURLOPT_HEADER => true, |
|
119 | CURLOPT_SSL_VERIFYHOST => 2, |
|
120 | CURLOPT_SSL_VERIFYPEER => true, |
|
121 | CURLOPT_POSTFIELDS => 'baz=bar', |
|
122 | ]); |
|
123 | ||
124 | if (count($caInfo) !== 1) { |
|
125 | return false; |
|
126 | } |
|
127 | ||
128 | if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) { |
|
129 | return false; |
|
130 | } |
|
131 | ||
132 | return true; |
|
133 | })) |
|
134 | ->once() |
|
135 | ->andReturn(null); |
|
136 | ||
137 | $this->curlClient->openConnection('http://bar.com', 'POST', 'baz=bar', [], 60); |
|
138 | } |
|
139 | ||
140 | public function testCanCloseConnection() |
|
141 | { |