|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Api\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use SlevomatCsobGateway\Api\ApiClientDriverException; |
|
6
|
|
|
use SlevomatCsobGateway\Api\HttpMethod; |
|
7
|
|
|
use SlevomatCsobGateway\Api\Response; |
|
8
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
|
9
|
|
|
|
|
10
|
|
|
class CurlDriverTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @runInSeparateProcess |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testRequest() |
|
17
|
|
|
{ |
|
18
|
|
|
include __DIR__ . '/CurlMock.php'; |
|
19
|
|
|
|
|
20
|
|
|
$curlDriver = new CurlDriver(); |
|
21
|
|
|
|
|
22
|
|
|
$response = $curlDriver->request( |
|
23
|
|
|
new HttpMethod(HttpMethod::POST), |
|
24
|
|
|
'foo/url', |
|
25
|
|
|
null, |
|
26
|
|
|
[ |
|
27
|
|
|
'Content-Type' => 'application/json', |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertInstanceOf(Response::class, $response); |
|
32
|
|
|
$this->assertSame(ResponseCode::S200_OK, $response->getResponseCode()->getValue()); |
|
33
|
|
|
$this->assertEquals([ |
|
34
|
|
|
'text' => 'foo text', |
|
35
|
|
|
], $response->getData()); |
|
36
|
|
|
$this->assertEquals([ |
|
37
|
|
|
'abc' => 'def', |
|
38
|
|
|
], $response->getHeaders()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @runInSeparateProcess |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testCurlDriverException() |
|
45
|
|
|
{ |
|
46
|
|
|
include __DIR__ . '/Curl_exec_false_Mock.php'; |
|
47
|
|
|
|
|
48
|
|
|
$curlDriver = new CurlDriver(); |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$response = $curlDriver->request( |
|
|
|
|
|
|
52
|
|
|
new HttpMethod(HttpMethod::POST), |
|
53
|
|
|
'foo/url', |
|
54
|
|
|
null, |
|
55
|
|
|
[ |
|
56
|
|
|
'Content-Type' => 'application/json', |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
} catch (CurlDriverException $e) { |
|
61
|
|
|
$this->assertInstanceOf(ApiClientDriverException::class, $e); |
|
62
|
|
|
$this->assertSame(11, $e->getCode()); |
|
63
|
|
|
$this->assertSame('foo getinfo', $e->getInfo()); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.