|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HelePartnerSyncApi\Request; |
|
4
|
|
|
|
|
5
|
|
|
use HelePartnerSyncApi\Client; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class RequestFactoryTest extends PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
public function testCreateRequest() |
|
12
|
|
|
{ |
|
13
|
|
|
$algo = 'sha1'; |
|
14
|
|
|
$secret = 'secret'; |
|
15
|
|
|
$arguments = array('value'); |
|
16
|
|
|
$method = 'fooMethod'; |
|
17
|
|
|
$data = array( |
|
18
|
|
|
Request::KEY_DATA => $arguments, |
|
19
|
|
|
Request::KEY_EXPECTED_VERSION => Client::VERSION, |
|
20
|
|
|
Request::KEY_METHOD => $method, |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
$requestData = json_encode($data); |
|
24
|
|
|
$requestFactory = new RequestFactory($secret); |
|
25
|
|
|
$request = $requestFactory->createRequest($requestData, array( |
|
26
|
|
|
Client::HEADER_SIGNATURE => hash_hmac($algo, $requestData, $secret), |
|
27
|
|
|
Client::HEADER_SIGNATURE_ALGORITHM => 'sha1', |
|
28
|
|
|
)); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertInstanceOf('HelePartnerSyncApi\Request\Request', $request); |
|
31
|
|
|
$this->assertSame($arguments, $request->getData()); |
|
32
|
|
|
$this->assertSame(Client::VERSION, $request->getExpectedVersion()); |
|
33
|
|
|
$this->assertSame($method, $request->getMethod()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @expectedException \HelePartnerSyncApi\Request\RequestException |
|
38
|
|
|
* @expectedExceptionMessage Missing X-Hele-Signature header in HTTP request |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testMissingSignatureHeader() |
|
41
|
|
|
{ |
|
42
|
|
|
$secret = 'secret'; |
|
43
|
|
|
$requestFactory = new RequestFactory($secret); |
|
44
|
|
|
$requestFactory->createRequest(json_encode(array()), array()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @expectedException \HelePartnerSyncApi\Request\RequestException |
|
49
|
|
|
* @expectedExceptionMessage Missing X-Hele-Signature-Algorithm header in HTTP request |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testMissingSignatureAlgorithmHeader() |
|
52
|
|
|
{ |
|
53
|
|
|
$secret = 'secret'; |
|
54
|
|
|
$requestFactory = new RequestFactory($secret); |
|
55
|
|
|
$requestFactory->createRequest(json_encode(array()), array( |
|
56
|
|
|
Client::HEADER_SIGNATURE => 'fooSignature', |
|
57
|
|
|
)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|