Completed
Push — refactoring ( f58f49 )
by Josef
45:19
created

RequestFactoryTest::testMissingSignatureHeader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
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
			'data' => $arguments,
19
			'expectedVersion' => Client::VERSION,
20
			'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 View Code Duplication
	public function testMissingSignatureHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
	{
38
		$secret = 'secret';
39
		$requestFactory = new RequestFactory($secret);
40
41
		try {
42
			$requestFactory->createRequest(json_encode(array()), array());
43
		} catch (RequestException $e) {
44
			$this->assertSame('Missing X-Hele-Signature header in HTTP request', $e->getMessage());
45
		}
46
	}
47
48 View Code Duplication
	public function testMissingSignatureAlgorithmHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
	{
50
		$secret = 'secret';
51
		$requestFactory = new RequestFactory($secret);
52
53
		try {
54
			$requestFactory->createRequest(json_encode(array()), array(
55
				Client::HEADER_SIGNATURE => 'fooSignature',
56
			));
57
		} catch (RequestException $e) {
58
			$this->assertSame('Missing X-Hele-Signature-Algorithm header in HTTP request', $e->getMessage());
59
		}
60
	}
61
62
}
63