GetEntitiesClientTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenNoIds_emptyArrayIsReturned() 0 8 1
A newHttpMockThatShouldNotBeCalled() 0 7 1
A testWhenHttpReturnsFalse_emptyArrayIsReturned() 0 14 1
A testGivenIds_urlHasIds() 0 10 1
A idAndUrlProvider() 0 12 1
1
<?php
2
3
namespace Tests\Queryr\Replicator\EntitySource\Api;
4
5
use PHPUnit\Framework\TestCase;
6
use Queryr\Replicator\EntitySource\Api\GetEntitiesClient;
7
use Queryr\Replicator\EntitySource\Api\Http;
8
9
/**
10
 * @covers \Queryr\Replicator\EntitySource\Api\GetEntitiesClient
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class GetEntitiesClientTest extends TestCase {
16
17
	public function testGivenNoIds_emptyArrayIsReturned() {
18
		$fetcher = new GetEntitiesClient( $this->newHttpMockThatShouldNotBeCalled() );
0 ignored issues
show
Documentation introduced by
$this->newHttpMockThatShouldNotBeCalled() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Queryr\Replicator\EntitySource\Api\Http>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
20
		$this->assertSame(
21
			[],
22
			$fetcher->fetchEntityPages( [] )
23
		);
24
	}
25
26
	private function newHttpMockThatShouldNotBeCalled() {
27
		$http = $this->createMock( Http::class );
28
29
		$http->expects( $this->never() )->method( 'get' );
30
31
		return $http;
32
	}
33
34
	public function testWhenHttpReturnsFalse_emptyArrayIsReturned() {
35
		$http = $this->createMock( Http::class );
36
37
		$http->expects( $this->any() )
38
				->method( 'get' )
39
				->willReturn( false );
40
41
		$fetcher = new GetEntitiesClient( $http );
0 ignored issues
show
Documentation introduced by
$http is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Queryr\Replicator\EntitySource\Api\Http>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
43
		$this->assertSame(
44
			[],
45
			$fetcher->fetchEntityPages( [] )
46
		);
47
	}
48
49
	/**
50
	 * @dataProvider idAndUrlProvider
51
	 */
52
	public function testGivenIds_urlHasIds( array $ids, $expectedUrl ) {
53
		$http = $this->createMock( Http::class );
54
55
		$http->expects( $this->once() )
56
			->method( 'get' )
57
			->with( $this->equalTo( $expectedUrl ) );
58
59
		$fetcher = new GetEntitiesClient( $http );
0 ignored issues
show
Documentation introduced by
$http is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Queryr\Replicator\EntitySource\Api\Http>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
		$fetcher->fetchEntityPages( $ids );
61
	}
62
63
	public function idAndUrlProvider() {
64
		return [
65
			[
66
				[ 'Q1' ],
67
				'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q1&format=json'
68
			],
69
			[
70
				[ 'Q1', 'Q2', 'Q3' ],
71
				'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q1|Q2|Q3&format=json'
72
			],
73
		];
74
	}
75
76
}