not->toBeEmpty(); }); // eval() here only wraps PHP regex-extracted from this repo's own cmd.php // (not external/user input) into a throwaway function. Test-only. Guarded // by function_exists() so re-running this file within the same process is safe. if (!function_exists('cmd_php_allhost_params3')) { eval('function cmd_php_allhost_params3(int $poller_interval, int $cron_interval, int $poller_id) { $allhost = true; ' . $allhostBlock[0] . ' return $params3; }'); } test('cron_interval == poller_interval resets rrd_next_step to 0', function () { $params3 = cmd_php_allhost_params3(300, 300, 1); expect($params3)->toBe([300, 300, 0, 300, 1]); }); test('cron_interval != poller_interval resets rrd_next_step to poller_interval, matching the ranged branch', function () { $params3 = cmd_php_allhost_params3(60, 300, 1); // before the fix this was hardcoded to 0 regardless of cron_interval expect($params3)->toBe([60, 60, 60, 60, 1]) ->and($params3[2])->not->toBe(0); }); // the extracted block above is the full if ($allhost) {...} else {...} // structure (the non-greedy match only stops at the bare top-level "}" that // closes the whole statement, since the if-branch's own closing brace is // immediately followed by " else {" on the same line, not a newline) -- so // the same extraction can drive the ranged branch too, just by flipping the // runtime $allhost flag the extracted code branches on. if (!function_exists('cmd_php_ranged_params3')) { eval('function cmd_php_ranged_params3(int $poller_interval, int $cron_interval, int $poller_id, $first, $last) { $allhost = false; ' . $allhostBlock[0] . ' return $params3; }'); } test('the $allhost and ranged branches compute the same $params3 for a given cron_interval/poller_interval pair', function () { $allhostParams = cmd_php_allhost_params3(60, 300, 1); $rangedParams = cmd_php_ranged_params3(60, 300, 1, 5, 10); // ranged appends $first/$last; the first 5 elements (the ones this fix // touches) must stay in parity between both branches expect(array_slice($rangedParams, 0, 5))->toBe($allhostParams); });