WikidataQueryApiTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 2
c 3
b 0
f 1
lcom 0
cbo 5
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testDoQuery() 0 25 1
A testDoQueryWithError() 0 19 1
1
<?php
2
3
namespace WikidataQueryApi;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Handler\MockHandler;
7
use GuzzleHttp\HandlerStack;
8
use GuzzleHttp\Psr7\Response;
9
10
/**
11
 * @covers WikidataQueryApi\WikidataQueryApi
12
 *
13
 * @licence GPLv2+
14
 * @author Thomas Pellissier Tanon
15
 */
16
class WikidataQueryApiTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testDoQuery() {
19
		$mock = new MockHandler( [
20
			new Response(
21
				200,
22
				[],
23
				json_encode( [
24
					'status' => [ 'error' => 'OK' ],
25
					'items' => [ 42 ]
26
				] )
27
			)
28
		] );
29
		$handler = HandlerStack::create( $mock );
30
		$client = new Client( [ 'handler' => $handler ] );
31
		$wikidataQueryApi = new WikidataQueryApi( '', $client );
32
33
		$this->assertEquals(
34
			[
35
				'status' => [ 'error' => 'OK' ],
36
				'items' => [ 42 ]
37
			],
38
			$wikidataQueryApi->doQuery( [
39
				'q' => 'claim[42:42]'
40
			] )
41
		);
42
	}
43
44
	public function testDoQueryWithError() {
45
		$mock = new MockHandler( [
46
			new Response(
47
				200,
48
				[],
49
				json_encode( [
50
					'status' => [ 'error' => 'Error' ]
51
				] )
52
			)
53
		] );
54
		$handler = HandlerStack::create( $mock );
55
		$client = new Client( [ 'handler' => $handler ] );
56
		$wikidataQueryApi = new WikidataQueryApi( '', $client );
57
58
		$this->setExpectedException( 'WikidataQueryApi\WikibaseQueryApiException' );
59
		$wikidataQueryApi->doQuery( [
60
			'q' => 'claim[42:42]'
61
		] );
62
	}
63
}
64