public function QueryBatchTest::queryDataProvider in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate/tests/src/Kernel/QueryBatchTest.php \Drupal\Tests\migrate\Kernel\QueryBatchTest::queryDataProvider()
- 9 core/modules/migrate/tests/src/Kernel/QueryBatchTest.php \Drupal\Tests\migrate\Kernel\QueryBatchTest::queryDataProvider()
File
- core/
modules/ migrate/ tests/ src/ Kernel/ QueryBatchTest.php, line 79
Class
- QueryBatchTest
- Tests query batching.
Namespace
Drupal\Tests\migrate\KernelCode
public function queryDataProvider() {
// Define the parameters for building the data array. The first element is
// the number of source data rows, the second is the batch size to set on
// the plugin configuration.
$test_parameters = [
// Test when batch size is 0.
[
200,
0,
],
// Test when rows mod batch size is 0.
[
200,
20,
],
// Test when rows mod batch size is > 0.
[
200,
30,
],
// Test when batch size = row count.
[
200,
200,
],
// Test when batch size > row count.
[
200,
300,
],
];
// Build the data provider array. The provider array consists of the source
// data rows, the expected result data, the expected count, the plugin
// configuration, the expected batch size and the expected batch count.
$table = 'query_batch_test';
$tests = [];
$data_set = 0;
foreach ($test_parameters as $data) {
[
$num_rows,
$batch_size,
] = $data;
for ($i = 0; $i < $num_rows; $i++) {
$tests[$data_set]['source_data'][$table][] = [
'id' => $i,
'data' => $this
->randomString(),
];
}
$tests[$data_set]['expected_data'] = $tests[$data_set]['source_data'][$table];
$tests[$data_set][2] = $num_rows;
// Plugin configuration array.
$tests[$data_set][3] = [
'batch_size' => $batch_size,
];
// Expected batch size.
$tests[$data_set][4] = $batch_size;
// Expected batch count is 0 unless a batch size is set.
$expected_batch_count = 0;
if ($batch_size > 0) {
$expected_batch_count = (int) ($num_rows / $batch_size);
if ($num_rows % $batch_size) {
// If there is a remainder an extra batch is needed to get the
// remaining rows.
$expected_batch_count++;
}
}
$tests[$data_set][5] = $expected_batch_count;
$data_set++;
}
return $tests;
}