diff --git a/src/Plugin/search_api/datasource/ContentEntity.php b/src/Plugin/search_api/datasource/ContentEntity.php
index ccf1c4b..1b6cb1c 100644
--- a/src/Plugin/search_api/datasource/ContentEntity.php
+++ b/src/Plugin/search_api/datasource/ContentEntity.php
@@ -746,6 +746,7 @@ protected function getBundleItemIds(array $bundles = NULL, $page = NULL) {
     }
     if (isset($page)) {
       $page_size = $this->getConfigValue('tracking_page_size');
+      assert('$page_size', 'Tracking page size is not set.');
       $select->range($page * $page_size, $page_size);
     }
     $entity_ids = $select->execute();
diff --git a/src/Tests/HooksTest.php b/src/Tests/HooksTest.php
index 8fb3db0..29edb6c 100644
--- a/src/Tests/HooksTest.php
+++ b/src/Tests/HooksTest.php
@@ -35,7 +35,9 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
 
     // Create an index and server to work with.
     $this->getTestServer();
diff --git a/src/Tests/LanguageIntegrationTest.php b/src/Tests/LanguageIntegrationTest.php
index 0b13999..6faaec0 100644
--- a/src/Tests/LanguageIntegrationTest.php
+++ b/src/Tests/LanguageIntegrationTest.php
@@ -35,7 +35,9 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
 
     // Create an index and server to work with.
     $this->getTestServer();
diff --git a/src/Tests/OverviewPageTest.php b/src/Tests/OverviewPageTest.php
index dc8a9df..1500823 100644
--- a/src/Tests/OverviewPageTest.php
+++ b/src/Tests/OverviewPageTest.php
@@ -29,7 +29,9 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
 
     $this->drupalLogin($this->adminUser);
 
diff --git a/tests/src/Kernel/BackendTestBase.php b/tests/src/Kernel/BackendTestBase.php
index 92c153f..4104736 100644
--- a/tests/src/Kernel/BackendTestBase.php
+++ b/tests/src/Kernel/BackendTestBase.php
@@ -65,7 +65,15 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
 
     $this->setUpExampleStructure();
   }
diff --git a/tests/src/Kernel/CliTest.php b/tests/src/Kernel/CliTest.php
index 50aa4c7..a7f6f3c 100644
--- a/tests/src/Kernel/CliTest.php
+++ b/tests/src/Kernel/CliTest.php
@@ -58,9 +58,12 @@ public function setUp() {
       ->getEditable('search_api.settings')
       ->set('tracking_page_size', 100)
       ->save();
+
     // Disable the use of batches for item tracking to simulate a CLI
     // environment.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
   }
 
   /**
diff --git a/tests/src/Kernel/CustomDataTypesTest.php b/tests/src/Kernel/CustomDataTypesTest.php
index e810123..5d93e7d 100644
--- a/tests/src/Kernel/CustomDataTypesTest.php
+++ b/tests/src/Kernel/CustomDataTypesTest.php
@@ -67,7 +67,15 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
 
     $this->installConfig(array('search_api_test_db'));
 
diff --git a/tests/src/Kernel/EntityStringIdTest.php b/tests/src/Kernel/EntityStringIdTest.php
index 8515cd0..de60f5a 100644
--- a/tests/src/Kernel/EntityStringIdTest.php
+++ b/tests/src/Kernel/EntityStringIdTest.php
@@ -72,7 +72,15 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
 
     // Create a test server.
     $this->server = Server::create(array(
diff --git a/tests/src/Kernel/IndexImportTest.php b/tests/src/Kernel/IndexImportTest.php
index 84eee4a..a361412 100644
--- a/tests/src/Kernel/IndexImportTest.php
+++ b/tests/src/Kernel/IndexImportTest.php
@@ -49,7 +49,15 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
 
     $this->installConfig(array('search_api_test_db'));
 
diff --git a/tests/src/Kernel/LanguageKernelTest.php b/tests/src/Kernel/LanguageKernelTest.php
index 87cd9c3..494a395 100644
--- a/tests/src/Kernel/LanguageKernelTest.php
+++ b/tests/src/Kernel/LanguageKernelTest.php
@@ -88,7 +88,15 @@ public function setUp() {
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
 
     // Create a test server.
     $this->server = Server::create(array(
diff --git a/tests/src/Kernel/Processor/ProcessorTestBase.php b/tests/src/Kernel/Processor/ProcessorTestBase.php
index 45188b7..4e93607 100644
--- a/tests/src/Kernel/Processor/ProcessorTestBase.php
+++ b/tests/src/Kernel/Processor/ProcessorTestBase.php
@@ -77,16 +77,19 @@ public function setUp($processor = NULL) {
       'plugin' => 'comment_publish_action',
     ])->save();
 
+    // Do not use a batch for tracking the initial items after creating an
+    // index when running the tests via the GUI. Otherwise, it seems Drupal's
+    // Batch API gets confused and the test fails.
+    if (php_sapi_name() != 'cli') {
+      \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
+    }
+
+    // Set tracking page size so tracking will work properly.
     \Drupal::configFactory()
       ->getEditable('search_api.settings')
       ->set('tracking_page_size', 100)
       ->save();
 
-    // Do not use a batch for tracking the initial items after creating an
-    // index when running the tests via the GUI. Otherwise, it seems Drupal's
-    // Batch API gets confused and the test fails.
-    \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
-
     $this->server = Server::create(array(
       'id' => 'server',
       'name' => 'Server & Name',
diff --git a/tests/src/Kernel/ServerTaskTest.php b/tests/src/Kernel/ServerTaskTest.php
index 2c589a5..4bfa220 100644
--- a/tests/src/Kernel/ServerTaskTest.php
+++ b/tests/src/Kernel/ServerTaskTest.php
@@ -73,6 +73,12 @@ public function setUp() {
     $this->installEntitySchema('user');
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
 
+    // Set tracking page size so tracking will work properly.
+    \Drupal::configFactory()
+      ->getEditable('search_api.settings')
+      ->set('tracking_page_size', 100)
+      ->save();
+
     // Create a test server.
     $this->server = Server::create(array(
       'name' => 'Test Server',
