toBe("'-v' '1' 'enterprise' '' '6' 'trap' ''"); }); test('built v1 trap command line keeps the correct argument count', function () { // -v 1 -c comm host:port enterprise "" 6 trap "" oid type value $args = ['-v', '1', '-c', 'public', 'h:162', 'ENT', '', '6', '99', '', 'oid', 's', 'val']; expect(shell_argc(snmptrap_escape_args($args)))->toBe(count($args)); }); test('built v2c trap command line keeps the correct argument count', function () { // -v 2c -c comm host:port "" enterprise oid type value $args = ['-v', '2c', '-c', 'public', 'h:162', '', 'ENT', 'oid', 's', 'val']; expect(shell_argc(snmptrap_escape_args($args)))->toBe(count($args)); }); test('the old space-join would drop the empty positions', function () { $args = ['-v', '1', 'enterprise', '', '6', 'trap', '']; // reproduce the pre-fix behaviour: empty tokens escape to '' (empty string) $broken = implode(' ', array_map(static function ($arg) { return $arg === '' ? '' : "'" . $arg . "'"; }, $args)); expect(shell_argc($broken))->toBeLessThan(count($args)); });