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() ); |
|
|
|
|
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 ); |
|
|
|
|
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 ); |
|
|
|
|
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
|
|
|
} |
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: