Completed
Push — master ( b08b65...b78d2e )
by mw
230:52 queued 205:17
created

testDoHttpPostForUnreachableDataEndpointThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\SPARQLStore\RepositoryConnectors;
4
5
use SMW\SPARQLStore\RepositoryClient;
6
7
/**
8
 * @covers \SMW\SPARQLStore\RepositoryConnectors\FusekiHttpRepositoryConnector
9
 * @covers \SMW\SPARQLStore\RepositoryConnectors\FourstoreHttpRepositoryConnector
10
 * @covers \SMW\SPARQLStore\RepositoryConnectors\VirtuosoHttpRepositoryConnector
11
 * @covers \SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector
12
 *
13
 * @group semantic-mediawiki
14
 *
15
 * @license GNU GPL v2+
16
 * @since 2.0
17
 *
18
 * @author mwjames
19
 */
20
class RepositoryConnectorsExceptionTest extends \PHPUnit_Framework_TestCase {
21
22
	private $defaultGraph;
23
24
	private $databaseConnectors = array(
25
		'\SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector',
26
		'\SMW\SPARQLStore\RepositoryConnectors\FusekiHttpRepositoryConnector',
27
		'\SMW\SPARQLStore\RepositoryConnectors\FourstoreHttpRepositoryConnector',
28
		'\SMW\SPARQLStore\RepositoryConnectors\VirtuosoHttpRepositoryConnector',
29
30
		// Legacy and should be removed once obsolete
31
		'SMWSparqlDatabase4Store',
32
		'SMWSparqlDatabaseVirtuoso',
33
		'SMWSparqlDatabase'
34
	);
35
36
	protected function setUp() {
37
		parent::setUp();
38
39
		$this->defaultGraph = 'http://foo/myDefaultGraph';
40
	}
41
42
	/**
43
	 * @dataProvider httpDatabaseConnectorInstanceNameProvider
44
	 */
45
	public function testCanConstruct( $httpConnector ) {
46
47
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$this->assertInstanceOf(
52
			'\SMW\SPARQLStore\RepositoryConnectors\GenericHttpRepositoryConnector',
53
			new $httpConnector( new RepositoryClient( $this->defaultGraph, '' ), $httpRequest )
54
		);
55
	}
56
57
	/**
58
	 * @dataProvider httpDatabaseConnectorInstanceNameProvider
59
	 */
60
	public function testDoQueryForEmptyQueryEndpointThrowsException( $httpConnector ) {
61
62
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
63
			->disableOriginalConstructor()
64
			->getMock();
65
66
		$instance = new $httpConnector(
67
			new RepositoryClient( $this->defaultGraph, '' ),
68
			$httpRequest
69
		);
70
71
		$this->setExpectedException( '\SMW\SPARQLStore\Exception\BadHttpDatabaseResponseException' );
72
		$instance->doQuery( '' );
73
	}
74
75
	/**
76
	 * @dataProvider httpDatabaseConnectorInstanceNameProvider
77
	 */
78
	public function testDoUpdateForEmptyUpdateEndpointThrowsException( $httpConnector ) {
79
80
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
81
			->disableOriginalConstructor()
82
			->getMock();
83
84
		$instance = new $httpConnector(
85
			new RepositoryClient( $this->defaultGraph, '', '' ),
86
			$httpRequest
87
		);
88
89
		$this->setExpectedException( '\SMW\SPARQLStore\Exception\BadHttpDatabaseResponseException' );
90
		$instance->doUpdate( '' );
91
	}
92
93
	/**
94
	 * @dataProvider httpDatabaseConnectorInstanceNameProvider
95
	 */
96
	public function testDoHttpPostForEmptyDataEndpointThrowsException( $httpConnector ) {
97
98
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
99
			->disableOriginalConstructor()
100
			->getMock();
101
102
		$instance = new $httpConnector(
103
			new RepositoryClient( $this->defaultGraph, '', '', '' ),
104
			$httpRequest
105
		);
106
107
		$this->setExpectedException( '\SMW\SPARQLStore\Exception\BadHttpDatabaseResponseException' );
108
		$instance->doHttpPost( '' );
109
	}
110
111
	/**
112
	 * @dataProvider httpDatabaseConnectorInstanceNameProvider
113
	 */
114
	public function testDoHttpPostForUnreachableDataEndpointThrowsException( $httpConnector ) {
115
116
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
117
			->disableOriginalConstructor()
118
			->getMock();
119
120
		$httpRequest->expects( $this->atLeastOnce() )
121
			->method( 'getLastErrorCode' )
122
			->will( $this->returnValue( 22 ) );
123
124
		$instance = new $httpConnector(
125
			new RepositoryClient( $this->defaultGraph, '', '', 'unreachableDataEndpoint' ),
126
			$httpRequest
127
		);
128
129
		$this->setExpectedException( 'Exception' );
130
		$instance->doHttpPost( '' );
131
	}
132
133
	public function httpDatabaseConnectorInstanceNameProvider() {
134
135
		$provider = array();
136
137
		foreach ( $this->databaseConnectors as $databaseConnector ) {
138
			$provider[] = array( $databaseConnector );
139
		}
140
141
		return $provider;
142
	}
143
144
}
145