20 $db->expects( $this->exactly(
count( $updates ) ) )
23 $writer->write( $updates );
29 'primaryKey' => [
'event_id' => $i++ ],
30 'changes' => $changes,
41 return [
'id_field' => ++$i ];
49 $this->assertEquals(
$response[$pos],
$rows,
"Testing row in position $pos" );
59 'some_col' =>
'dvorak',
60 'other_col' =>
'samurai',
65 'Must return single column pk when requested',
71 'Must return multiple column pks when requested',
72 [
'id_field' => 42,
'other_col' =>
'samurai' ],
84 $this->assertEquals( $expected, $reader->extractPrimaryKeys( (
object)$row ), $message );
91 'Must merge primary keys into select conditions',
101 'Must not merge primary keys into the all columns selector',
111 'Must not duplicate primary keys into column selector',
114 [ 0 =>
'foo', 1 =>
'bar', 3 =>
'baz' ],
130 $db->expects( $this->once() )
133 ->with(
'some_table', $columns )
134 ->will( $this->returnValue(
new ArrayIterator( [] ) ) );
137 $reader->setFetchColumns( $fetchColumns );
146 "With single primary key must generate id > 'value'",
148 [
"( id_field > '3' )" ],
154 'With multiple primary keys the first conditions ' .
155 'must use >= and the final condition must use >',
157 [
"( id_field = '3' AND foo > '103' ) OR ( id_field > '3' )" ],
159 [
'id_field',
'foo' ],
172 $message, $expectedSecondIteration, $primaryKeys, $batchSize = 3
174 $results = $this->
genSelectResult( $batchSize, $batchSize * 3,
function () {
175 static $i = 0, $j = 100, $k = 1000;
176 return [
'id_field' => ++$i,
'foo' => ++$j,
'bar' => ++$k ];
180 $conditions = [
'bar' => 42,
'baz' =>
'hai' ];
182 $reader->addConditions( $conditions );
184 $buildConditions =
new ReflectionMethod( $reader,
'buildConditions' );
185 $buildConditions->setAccessible(
true );
188 $this->assertEquals( $conditions, $buildConditions->invoke( $reader ),
189 'First iteration must return only the conditions passed in addConditions' );
194 $conditions + $expectedSecondIteration,
195 $buildConditions->invoke( $reader ),
202 $db->expects( $this->
any() )
205 $db->expects( $this->
any() )
206 ->method(
'addQuotes' )
207 ->will( $this->returnCallback(
function (
$value ) {
216 foreach ( $results
as $rows ) {
218 $retvals[] = $this->returnValue(
new ArrayIterator(
$rows ) );
221 return call_user_func_array( [ $this,
'onConsecutiveCalls' ], $retvals );
226 for ( $i = 0; $i < $numRows; $i += $batchSize ) {
228 for ( $j = 0; $j < $batchSize && $i + $j < $numRows; $j++ ) {
229 $rows [] = (
object)call_user_func( $rowGenerator );
240 $databaseMysql = $this->getMockBuilder(
'DatabaseMysqli' )
241 ->disableOriginalConstructor()
243 $databaseMysql->expects( $this->
any() )
245 ->will( $this->returnValue(
true ) );
246 $databaseMysql->expects( $this->
any() )
247 ->method(
'getApproximateLagStatus' )
248 ->will( $this->returnValue( [
'lag' => 0,
'since' => 0 ] ) );
249 return $databaseMysql;