Completed
Push — master ( 06ed76...0f3f4f )
by WEBEWEB
06:00 queued 14s
created

CURLConfigurationTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 146
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the curl-library package.
5
 *
6
 * (c) 2017 NdC/WBW
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\CURL\Tests\Configuration;
13
14
use Exception;
15
use PHPUnit_Framework_TestCase;
16
use WBW\Library\Core\Exception\Argument\StringArgumentException;
17
use WBW\Library\CURL\Configuration\CURLConfiguration;
18
19
/**
20
 * CURL configuration test.
21
 *
22
 * @author NdC/WBW <https://github.com/webeweb/>
23
 * @package WBW\Library\CURL\Tests\Configuration
24
 * @final
25
 */
26
final class CURLConfigurationTest extends PHPUnit_Framework_TestCase {
27
28
	/**
29
	 * Tests the __constructor() method.
30
	 *
31
	 * @return void
32
	 */
33
	public function testConstructor() {
34
35
		$obj = new CURLConfiguration();
36
37
		$this->assertEquals(false, $obj->getAllowEncoding());
38
		$this->assertEquals(0, $obj->getConnectTimeout());
39
		$this->assertEquals(false, $obj->getDebug());
40
		$this->assertEquals("php://output", $obj->getDebugFile());
41
		$this->assertEquals([], $obj->getHeaders());
42
		$this->assertEquals(null, $obj->getHost());
43
		$this->assertEquals(null, $obj->getHttpPassword());
44
		$this->assertEquals(null, $obj->getHttpUsername());
45
		$this->assertEquals(null, $obj->getProxyHost());
46
		$this->assertEquals(null, $obj->getProxyPassword());
47
		$this->assertEquals(null, $obj->getProxyPort());
48
		$this->assertEquals(null, $obj->getProxyType());
49
		$this->assertEquals(null, $obj->getProxyUsername());
50
		$this->assertEquals(0, $obj->getRequestTimeout());
51
		$this->assertEquals(true, $obj->getSslVerification());
52
		$this->assertEquals("cURLLibrary/1.0", $obj->getUserAgent());
53
		$this->assertEquals(false, $obj->getVerbose());
54
	}
55
56
	/**
57
	 * Tests the addHeader() method.
58
	 *
59
	 * @return void
60
	 */
61
	public function testAddHeader() {
62
63
		$obj = new CURLConfiguration();
64
65
		$obj->addHeader("name", "value");
66
		$res1 = ["name" => "value"];
67
		$this->assertEquals($res1, $obj->getHeaders());
68
69
		try {
70
			$obj->addHeader(1, "value");
71
		} catch (Exception $ex) {
72
			$this->assertInstanceOf(StringArgumentException::class, $ex);
73
			$this->assertEquals("The argument \"1\" is not a string", $ex->getMessage());
74
		}
75
	}
76
77
	/**
78
	 * Tests the clearHeader() method.
79
	 *
80
	 * @return void
81
	 */
82
	public function testClearHeaders() {
83
84
		$obj = new CURLConfiguration();
85
86
		$obj->addHeader("name", "value");
87
		$this->assertCount(1, $obj->getHeaders());
88
89
		$obj->clearHeaders();
90
		$this->assertCount(0, $obj->getHeaders());
91
	}
92
93
	/**
94
	 * Tests the removeHeader() method.
95
	 *
96
	 * @return void
97
	 */
98
	public function testRemoveHeader() {
99
100
		$obj = new CURLConfiguration();
101
		$obj->addHeader("name", "value");
102
103
		$obj->removeHeader("");
104
		$res1 = ["name" => "value"];
105
		$this->assertEquals($res1, $obj->getHeaders());
106
107
		$obj->removeHeader("name");
108
		$res2 = [];
109
		$this->assertEquals($res2, $obj->getHeaders());
110
	}
111
112
	/**
113
	 * Tests the setX() method.
114
	 *
115
	 * @return void
116
	 */
117
	public function testSetX() {
118
119
		$obj = new CURLConfiguration();
120
121
122
		$obj->setAllowEncoding(true);
123
		$this->assertEquals(true, $obj->getAllowEncoding());
124
125
		$obj->setConnectTimeout(1);
126
		$this->assertEquals(1, $obj->getConnectTimeout());
127
128
		$obj->setDebug(true);
129
		$this->assertEquals(true, $obj->getDebug());
130
131
		$obj->setDebugFile("./debugfile.log");
132
		$this->assertEquals("./debugfile.log", $obj->getDebugFile());
133
134
		$obj->setHost("host");
135
		$this->assertEquals("host", $obj->getHost());
136
137
		$obj->setHttpPassword("httpPassword");
138
		$this->assertEquals("httpPassword", $obj->getHttpPassword());
139
140
		$obj->setHttpUsername("httpUsername");
141
		$this->assertEquals("httpUsername", $obj->getHttpUsername());
142
143
		$obj->setProxyHost("proxyHost");
144
		$this->assertEquals("proxyHost", $obj->getProxyHost());
145
146
		$obj->setProxyPassword("proxyPassword");
147
		$this->assertEquals("proxyPassword", $obj->getProxyPassword());
148
149
		$obj->setProxyPort("proxyPort");
150
		$this->assertEquals("proxyPort", $obj->getProxyPort());
151
152
		$obj->setProxyType(1);
153
		$this->assertEquals(1, $obj->getProxyType());
154
155
		$obj->setProxyUsername("proxyUsername");
156
		$this->assertEquals("proxyUsername", $obj->getProxyUsername());
157
158
		$obj->setRequestTimeout(1);
159
		$this->assertEquals(1, $obj->getRequestTimeout());
160
161
		$obj->setSslVerification(false);
162
		$this->assertEquals(false, $obj->getSslVerification());
163
164
		$obj->setUserAgent("userAgent");
165
		$this->assertEquals("userAgent", $obj->getUserAgent());
166
167
		$obj->setVerbose(true);
168
		$this->assertEquals(true, $obj->getVerbose());
169
	}
170
171
}
172