CurlRequestTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 92
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 14 1
A testWrongResourceTypeThrowsException() 0 4 1
A testPing() 0 15 1
A testGetLastError() 0 9 1
A testGetLastErrorCode() 0 9 1
A testExecuteForNullUrl() 0 21 1
A testSetOptionUsingOnoiSpecificConstantDoesNotCauseAnyFailureWithCurl_Setopt() 0 10 1
1
<?php
2
3
namespace Onoi\HttpRequest\Tests;
4
5
use Onoi\HttpRequest\CurlRequest;
6
7
/**
8
 * @covers \Onoi\HttpRequest\CurlRequest
9
 * @group onoi-http-request
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class CurlRequestTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$instance = new CurlRequest( curl_init() );
21
22
		$this->assertInstanceOf(
23
			'\Onoi\HttpRequest\CurlRequest',
24
			$instance
25
		);
26
27
		$this->assertInstanceOf(
28
			'\Onoi\HttpRequest\HttpRequest',
29
			$instance
30
		);
31
	}
32
33
	public function testWrongResourceTypeThrowsException() {
34
		$this->setExpectedException( 'InvalidArgumentException' );
35
		new CurlRequest( curl_multi_init() );
36
	}
37
38
	public function testPing() {
39
40
		$instance = new CurlRequest( curl_init() );
41
42
		$this->assertFalse(
43
			$instance->ping()
44
		);
45
46
		$instance->setOption( CURLOPT_URL, 'http://example.org' );
47
48
		$this->assertInternalType(
49
			'boolean',
50
			$instance->ping()
51
		);
52
	}
53
54
	public function testGetLastError() {
55
56
		$instance = new CurlRequest( curl_init() );
57
58
		$this->assertInternalType(
59
			'string',
60
			$instance->getLastError()
61
		);
62
	}
63
64
	public function testGetLastErrorCode() {
65
66
		$instance = new CurlRequest( curl_init() );
67
68
		$this->assertInternalType(
69
			'integer',
70
			$instance->getLastErrorCode()
71
		);
72
	}
73
74
	public function testExecuteForNullUrl() {
75
76
		$instance = new CurlRequest( curl_init( null ) );
77
		$instance->setOption( CURLOPT_RETURNTRANSFER, true );
78
79
		$this->assertTrue(
80
			$instance->getOption( CURLOPT_RETURNTRANSFER )
81
		);
82
83
		$this->assertFalse(
84
			$instance->execute()
85
		);
86
87
		$this->assertNull(
88
			$instance->getOption( CURLOPT_RETURNTRANSFER )
89
		);
90
91
		$this->assertEmpty(
92
			$instance->getLastTransferInfo( CURLINFO_HTTP_CODE )
93
		);
94
	}
95
96
	public function testSetOptionUsingOnoiSpecificConstantDoesNotCauseAnyFailureWithCurl_Setopt() {
97
98
		$instance = new CurlRequest( curl_init( null ) );
99
		$instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 );
100
101
		$this->assertEquals(
102
			42,
103
			$instance->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL )
104
		);
105
	}
106
107
}
108