|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Replicator\EntitySource\Api; |
|
4
|
|
|
|
|
5
|
|
|
use BatchingIterator\BatchingIterator; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Queryr\Replicator\EntitySource\BatchingEntityPageFetcher; |
|
8
|
|
|
use Queryr\Replicator\EntitySource\EntityPageBatchFetcher; |
|
9
|
|
|
use Tests\Queryr\Replicator\Fixtures\FakeEntityPagesFetcher; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \Queryr\Replicator\EntitySource\BatchingEntityPageFetcher |
|
13
|
|
|
* |
|
14
|
|
|
* @licence GNU GPL v2+ |
|
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class ApiEntityPageIteratorTest extends TestCase { |
|
18
|
|
|
|
|
19
|
|
|
public function testIterationOverEmptyIterator() { |
|
20
|
|
|
$iterator = $this->newFakeIterator( [], [] ); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame( [], iterator_to_array( $iterator ) ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function newFakeIterator( array $pages, array $pagesToFetch ) { |
|
26
|
|
|
return new BatchingIterator( new BatchingEntityPageFetcher( |
|
27
|
|
|
new FakeEntityPagesFetcher( $pages ), |
|
28
|
|
|
$pagesToFetch |
|
29
|
|
|
) ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testWhenNoPagesAreFound_iteratorIsEmpty() { |
|
33
|
|
|
$iterator = $this->newFakeIterator( [], [ 'Q1', 'Q2' ] ); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertSame( [], iterator_to_array( $iterator ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @dataProvider batchProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testCorrectAmountOfCallsAreMadeToTheBatchFetcher( array $ids, $maxBatchSize, $expectedCallCount ) { |
|
42
|
|
|
$fetcher = $this->newFetcherMock(); |
|
43
|
|
|
|
|
44
|
|
|
$fetcher->expects( $this->exactly( $expectedCallCount ) ) |
|
45
|
|
|
->method( 'fetchEntityPages' ) |
|
46
|
|
|
->will( $this->returnArgument( 0 ) ); |
|
47
|
|
|
|
|
48
|
|
|
$iterator = new BatchingIterator( new BatchingEntityPageFetcher( |
|
49
|
|
|
$fetcher, |
|
|
|
|
|
|
50
|
|
|
$ids |
|
51
|
|
|
) ); |
|
52
|
|
|
|
|
53
|
|
|
$iterator->setMaxBatchSize( $maxBatchSize ); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertSame( |
|
56
|
|
|
$ids, |
|
57
|
|
|
iterator_to_array( $iterator ) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function newFetcherMock() { |
|
62
|
|
|
return $this->createMock( EntityPageBatchFetcher::class ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function batchProvider() { |
|
66
|
|
|
return [ |
|
67
|
|
|
[ |
|
68
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4', 'Q5' ], |
|
69
|
|
|
5, |
|
70
|
|
|
1 |
|
71
|
|
|
], |
|
72
|
|
|
|
|
73
|
|
|
[ |
|
74
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4', 'Q5' ], |
|
75
|
|
|
1, |
|
76
|
|
|
5 |
|
77
|
|
|
], |
|
78
|
|
|
|
|
79
|
|
|
[ |
|
80
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4', 'Q5' ], |
|
81
|
|
|
2, |
|
82
|
|
|
3 |
|
83
|
|
|
], |
|
84
|
|
|
|
|
85
|
|
|
[ |
|
86
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4', 'Q5' ], |
|
87
|
|
|
3, |
|
88
|
|
|
2 |
|
89
|
|
|
], |
|
90
|
|
|
|
|
91
|
|
|
[ |
|
92
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4', 'Q5' ], |
|
93
|
|
|
10, |
|
94
|
|
|
1 |
|
95
|
|
|
], |
|
96
|
|
|
|
|
97
|
|
|
[ |
|
98
|
|
|
[ 'Q1', 'Q2', 'Q3', 'Q4' ], |
|
99
|
|
|
2, |
|
100
|
|
|
2 |
|
101
|
|
|
], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
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: