CurlDriverTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 26
c 3
b 0
f 0
dl 0
loc 52
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRequest() 0 22 1
A testCurlDriverException() 0 19 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Api\Driver;
4
5
use PHPUnit\Framework\TestCase;
6
use SlevomatCsobGateway\Api\HttpMethod;
7
use SlevomatCsobGateway\Api\ResponseCode;
8
9
class CurlDriverTest extends TestCase
10
{
11
12
	/**
13
	 * @runInSeparateProcess
14
	 */
15
	public function testRequest(): void
16
	{
17
		include __DIR__ . '/CurlMock.php';
18
19
		$curlDriver = new CurlDriver();
20
21
		$response = $curlDriver->request(
22
			HttpMethod::get(HttpMethod::POST),
23
			'foo/url',
24
			null,
25
			[
26
				'Content-Type' => 'application/json',
27
			]
28
		);
29
30
		self::assertSame(ResponseCode::S200_OK, $response->getResponseCode()->getValue());
31
		self::assertEquals([
32
			'text' => 'foo text',
33
		], $response->getData());
34
		self::assertEquals([
35
			'abc' => 'def',
36
		], $response->getHeaders());
37
	}
38
39
	/**
40
	 * @runInSeparateProcess
41
	 */
42
	public function testCurlDriverException(): void
43
	{
44
		include __DIR__ . '/Curl_exec_false_Mock.php';
45
46
		$curlDriver = new CurlDriver();
47
48
		try {
49
			$curlDriver->request(
50
				HttpMethod::get(HttpMethod::POST),
51
				'foo/url',
52
				null,
53
				[
54
					'Content-Type' => 'application/json',
55
				]
56
			);
57
58
		} catch (CurlDriverException $e) {
59
			self::assertSame(11, $e->getCode());
60
			self::assertSame('foo getinfo', $e->getInfo());
61
		}
62
	}
63
64
}
65