@@ -12,6 +12,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
12
12
private $ host ;
13
13
/** @var array */
14
14
private $ headers ;
15
+ /** @var array */
16
+ private $ errors ;
15
17
16
18
protected function setUp ()
17
19
{
@@ -21,6 +23,24 @@ protected function setUp()
21
23
'Authorization: Bearer SG.XXXX '
22
24
];
23
25
$ this ->client = new MockClient ($ this ->host , $ this ->headers , '/v3 ' );
26
+ $ this ->errors = [];
27
+ set_error_handler ([$ this , 'errorHandler ' ]);
28
+ }
29
+
30
+ public function errorHandler ($ errno , $ errstr , $ errfile , $ errline , $ errcontext )
31
+ {
32
+ $ this ->errors [] = compact ('errno ' , 'errstr ' , 'errfile ' , 'errline ' , 'errcontext ' );
33
+ }
34
+
35
+ public function assertError ($ expectedErrorStringRegex , $ expectedErrorNumber )
36
+ {
37
+ foreach ($ this ->errors as $ error ) {
38
+ if ($ error ['errno ' ] === $ expectedErrorNumber && preg_match ($ expectedErrorStringRegex , $ error ['errstr ' ])) {
39
+ return $ this ->assertTrue (true );
40
+ }
41
+ }
42
+
43
+ $ this ->fail (sprintf ('Error with level "%d" matching "%s" was not triggered ' , $ expectedErrorNumber , $ expectedErrorStringRegex ));
24
44
}
25
45
26
46
public function testConstructor ()
@@ -195,6 +215,14 @@ public function testCreateCurlOptionsWithBodyAndHeaders()
195
215
], $ result );
196
216
}
197
217
218
+ public function testMakeRequestWithUntrustedRootCert ()
219
+ {
220
+ $ client = new Client ('https://untrusted-root.badssl.com/ ' );
221
+ $ client ->makeRequest ('GET ' , 'https://untrusted-root.badssl.com/ ' );
222
+
223
+ $ this ->assertError ('/certificate/i ' , E_USER_ERROR );
224
+ }
225
+
198
226
/**
199
227
* @param object $obj
200
228
* @param string $name
0 commit comments