Completed
Pull Request — master (#5)
by Jan
17:34 queued 02:37
created

CurlDriverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 1
cbo 6
dl 0
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testRequest() 0 24 1
A testCurlDriverException() 0 22 2
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(
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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