<?php

/**
 * @file
 * Install hooks for test module.
 */

use Drupal\entity_test\Entity\EntityTest;

/**
 * Implements hook_install().
 */
function test_batch_test_install() {
  $total = 2;
  $operations = [];
  for ($i = 1; $i <= $total; $i++) {
    $operations[] = ['_test_batch_test_callback', [$i]];
  }
  $batch = [
    'operations' => $operations,
  ];
  batch_set($batch);
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  batch_process();
}

/**
 * Callback for batch operations.
 */
function _test_batch_test_callback($id) {
  $entity = EntityTest::create(['id' => $id]);
  $entity->save();
}
