WikidataQueryApiTest::testDoQueryWithError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 1
eloc 12
c 3
b 0
f 1
nc 1
nop 0
dl 0
loc 19
rs 9.4285
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