toContain('private function getDefaultAutomationTemplateIds() : array') ->toContain('WHERE hash IN ($placeholders)') ->toContain('$template_ids = $this->getDefaultAutomationTemplateIds();') ->not->toContain("db_fetch_cell_prepared('SELECT id\n\t\t\t\t\tFROM host_template\n\t\t\t\t\tWHERE hash = ?'"); }); test('automation mappings are loaded once before the template loop', function () use ($source) { expect($source) ->toContain('WHERE host_template IN ($placeholders)') ->toContain('if (!isset($mapped_ids[$host_template_id]))') ->not->toContain("db_fetch_cell_prepared('SELECT host_template\n\t\t\t\t\t\tFROM automation_templates"); }); test('collector names are fetched in one query while preserving log order', function () use ($source) { if (preg_match('/private static function fullSyncDataCollectorLog\(.*?^\t}\R/ms', $source, $matches) !== 1) { throw new RuntimeException('Unable to extract fullSyncDataCollectorLog() for SQL batching tests.'); } expect($matches[0]) ->toContain('WHERE id IN ($placeholders)') ->toContain('foreach ($poller_ids as $id)') ->toContain('$poller = $pollers[$id] ?? false;') ->not->toContain('SELECT name FROM poller WHERE id = ?'); });