From c54f88555832a6daef5653dfa64e0e67d1679ea3 Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 14 Mar 2024 17:21:23 +0100 Subject: [PATCH 1/5] Refactor Options Parser and default Options Handler Refactor default Options Handler to accept dependencies through its constructor. Refactor default Options Handler to return an array of options instead of directly setting options in Config and declare array return types. Refactor method in Options Parser to return an array of options and declare its return type as array. Inject all necessary dependencies in render.php. Refactor two methods in default Options Handler by using match expressions. --- phpdotnet/phd/Options/Handler.php | 388 +++++++++++++++++++----------- phpdotnet/phd/Options/Parser.php | 19 +- render.php | 9 +- 3 files changed, 262 insertions(+), 154 deletions(-) diff --git a/phpdotnet/phd/Options/Handler.php b/phpdotnet/phd/Options/Handler.php index 5cc50532..2db56e37 100644 --- a/phpdotnet/phd/Options/Handler.php +++ b/phpdotnet/phd/Options/Handler.php @@ -3,6 +3,11 @@ class Options_Handler implements Options_Interface { + public function __construct( + private Config $config, + private Format_Factory $formatFactory + ) {} + /** * @return array */ @@ -36,26 +41,37 @@ public function optionList(): array ]; } - public function option_M(string $k, mixed $v): void + /** + * @return array + */ + public function option_M(string $k, mixed $v): array { - $this->option_memoryindex($k, $v); + return $this->option_memoryindex($k, $v); } - public function option_memoryindex(string $k, mixed $v): void + /** + * @return array + */ + public function option_memoryindex(string $k, mixed $v): array { - Config::set_memoryindex(true); + return ['memoryindex' => true]; } - public function option_f(string $k, mixed $v): void + /** + * @return array> + */ + public function option_f(string $k, mixed $v): array { if ($k === "f") { - $this->option_format($k, $v); - return; + return $this->option_format($k, $v); } - $this->option_outputfilename($k, $v); + return $this->option_outputfilename($k, $v); } - public function option_format(string $k, mixed $v): void + /** + * @return array> + */ + public function option_format(string $k, mixed $v): array { $formats = []; foreach((array)$v as $i => $val) { @@ -63,74 +79,108 @@ public function option_format(string $k, mixed $v): void $formats[] = $val; } } - Config::set_output_format($formats); + return ['output_format' => $formats]; } - public function option_e(string $k, mixed $v): void + /** + * @return array + */ + public function option_e(string $k, mixed $v): array { - $this->option_ext($k, $v); + return $this->option_ext($k, $v); } - public function option_ext(string $k, mixed $v): void + /** + * @return array + */ + public function option_ext(string $k, mixed $v): array { - $bool = self::boolval($v); - if ($bool === false) { - // `--ext=false` means no extension will be used - $v = ""; - Config::setExt($v); - } elseif ($bool === null) { - // `--ext=true` means use the default extension, - // `--ext=".foo"` means use ".foo" as the extension - Config::setExt($v); - } + // `--ext=false`: no extension will be used + // `--ext=true`: use the default extension + // `--ext=".foo"`: use the ".foo" extension + return match (self::boolval($v)) { + false => ['ext' => ''], + true => ['ext' => null], + null => ['ext' => $v] + }; } - public function option_g(string $k, mixed $v): void + /** + * @return array + */ + public function option_g(string $k, mixed $v): array { - $this->option_highlighter($k, $v); + return $this->option_highlighter($k, $v); } - public function option_highlighter(string $k, mixed $v): void + /** + * @return array + */ + public function option_highlighter(string $k, mixed $v): array { - Config::setHighlighter($v); + return ['highlighter' => $v]; } - public function option_i(string $k, mixed $v): void + /** + * @return array + */ + public function option_i(string $k, mixed $v): array { - $this->option_noindex($k, 'true'); + return $this->option_noindex($k, $v); } - public function option_noindex(string $k, mixed $v): void + /** + * @return array + */ + public function option_noindex(string $k, mixed $v): array { - Config::set_no_index(true); + return ['no_index' => true]; } - public function option_r(string $k, mixed $v): void + /** + * @return array + */ + public function option_r(string $k, mixed $v): array { - $this->option_forceindex($k, 'true'); + return $this->option_forceindex($k, $v); } - public function option_forceindex(string $k, mixed $v): void + /** + * @return array + */ + public function option_forceindex(string $k, mixed $v): array { - Config::set_force_index(true); + return ['force_index' => true]; } - public function option_t(string $k, mixed $v): void + /** + * @return array + */ + public function option_t(string $k, mixed $v): array { - $this->option_notoc($k, 'true'); + return $this->option_notoc($k, $v); } - public function option_notoc(string $k, mixed $v): void + /** + * @return array + */ + public function option_notoc(string $k, mixed $v): array { - Config::set_no_toc(true); + return ['no_toc' => true]; } - public function option_d(string $k, mixed $v): void + /** + * @return array + */ + public function option_d(string $k, mixed $v): array { - $this->option_docbook($k, $v); + return $this->option_docbook($k, $v); } - public function option_docbook(string $k, mixed $v): void + /** + * @return array + */ + public function option_docbook(string $k, mixed $v): array { if (is_array($v)) { trigger_error("Can only parse one file at a time", E_USER_ERROR); @@ -138,16 +188,24 @@ public function option_docbook(string $k, mixed $v): void if (!file_exists($v) || is_dir($v) || !is_readable($v)) { trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR); } - Config::set_xml_root(dirname($v)); - Config::set_xml_file($v); + return [ + 'xml_root' => dirname($v), + 'xml_file' => $v, + ]; } - public function option_o(string $k, mixed $v): void + /** + * @return array + */ + public function option_o(string $k, mixed $v): array { - $this->option_output($k, $v); + return $this->option_output($k, $v); } - public function option_output(string $k, mixed $v): void + /** + * @return array + */ + public function option_output(string $k, mixed $v): array { if (is_array($v)) { trigger_error("Only a single output location can be supplied", E_USER_ERROR); @@ -159,32 +217,41 @@ public function option_output(string $k, mixed $v): void trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR); } $v = (substr($v, strlen($v) - strlen(DIRECTORY_SEPARATOR)) === DIRECTORY_SEPARATOR) ? $v : ($v . DIRECTORY_SEPARATOR); - Config::set_output_dir($v); + + return ['output_dir' => $v]; } - public function option_outputfilename(string $k, mixed $v): void + /** + * @return array + */ + public function option_outputfilename(string $k, mixed $v): array { if (is_array($v)) { trigger_error("Only a single output location can be supplied", E_USER_ERROR); } $file = basename($v); - Config::set_output_filename($file); + return ['output_filename' => $file]; } - public function option_p(string $k, mixed $v): void + /** + * @return array + */ + public function option_p(string $k, mixed $v): array { if ($k === "P") { - $this->option_package($k, $v); - return; + return $this->option_package($k, $v); } - $this->option_partial($k, $v); + return $this->option_partial($k, $v); } - public function option_partial(string $k, mixed $v): void + /** + * @return array> + */ + public function option_partial(string $k, mixed $v): array { - $render_ids = Config::render_ids(); - foreach((array)$v as $i => $val) { + $render_ids = $this->config->render_ids(); + foreach((array)$v as $val) { $recursive = true; if (strpos($val, "=") !== false) { list($val, $recursive) = explode("=", $val); @@ -196,42 +263,56 @@ public function option_partial(string $k, mixed $v): void } $render_ids[$val] = $recursive; } - Config::set_render_ids($render_ids); + return ['render_ids' => $render_ids]; } - public function option_package(string $k, mixed $v): void + /** + * @return array> + */ + public function option_package(string $k, mixed $v): array { foreach((array)$v as $package) { - if (!in_array($package, Config::getSupportedPackages())) { - $supported = implode(', ', Config::getSupportedPackages()); + if (!in_array($package, $this->config->getSupportedPackages())) { + $supported = implode(', ', $this->config->getSupportedPackages()); trigger_error("Invalid Package (Tried: '$package' Supported: '$supported')", E_USER_ERROR); } } - Config::set_package($v); + return ['package' => (array) $v]; } - public function option_q(string $k, mixed $v): void + /** + * @return array + */ + public function option_q(string $k, mixed $v): array { - $this->option_quit($k, $v); + return $this->option_quit($k, $v); } - public function option_quit(string $k, mixed $v): void + /** + * @return array + */ + public function option_quit(string $k, mixed $v): array { - Config::set_quit(true); + return ['quit' => true]; } - public function option_s(string $k, mixed $v): void + /** + * @return array> + */ + public function option_s(string $k, mixed $v): array { if ($k === "S") { - $this->option_saveconfig($k, $v); - return; + return $this->option_saveconfig($k, $v); } - $this->option_skip($k, $v); + return $this->option_skip($k, $v); } - public function option_skip(string $k, mixed $v): void + /** + * @return array> + */ + public function option_skip(string $k, mixed $v): array { - $skip_ids = Config::skip_ids(); + $skip_ids = $this->config->skip_ids(); foreach((array)$v as $i => $val) { $recursive = true; if (strpos($val, "=") !== false) { @@ -244,38 +325,42 @@ public function option_skip(string $k, mixed $v): void } $skip_ids[$val] = $recursive; } - Config::set_skip_ids($skip_ids); + return ['skip_ids' => $skip_ids]; } - public function option_saveconfig(string $k, mixed $v): void + /** + * @return array + */ + public function option_saveconfig(string $k, mixed $v): array { if (is_array($v)) { trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); } - // No arguments passed, default to 'true' - if (is_bool($v)) { - $v = "true"; - } + $val = is_bool($v) ? true : self::boolval($v); - $val = self::boolval($v); - if (is_bool($val)) { - Config::set_saveconfig($v); - } else { + if (!is_bool($val)) { trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); } + + return ['saveconfig' => $val]; } - public function option_v(string $k, mixed $v): void + /** + * @return array + */ + public function option_v(string $k, mixed $v): array { if ($k[0] === 'V') { - $this->option_version($k, $v); - return; + return $this->option_version($k, $v); } - $this->option_verbose($k, $v); + return $this->option_verbose($k, $v); } - public function option_verbose(string $k, mixed $v): void + /** + * @return array + */ + public function option_verbose(string $k, mixed $v): array { static $verbose = 0; @@ -293,60 +378,72 @@ public function option_verbose(string $k, mixed $v): void } } } - Config::set_verbose($verbose); error_reporting($GLOBALS['olderrrep'] | $verbose); + return ['verbose' => $verbose]; } - public function option_l(string $k, mixed $v): void + /** + * @return array + */ + public function option_l(string $k, mixed $v): array { if ($k === "L") { - $this->option_lang($k, $v); - return; + return $this->option_lang($k, $v); } - $this->option_list($k, $v); + return $this->option_list($k, $v); } public function option_list(string $k, mixed $v): never { - $packageList = Config::getSupportedPackages(); + $packageList = $this->config->getSupportedPackages(); echo "Supported packages:\n"; foreach ($packageList as $package) { - $formats = Format_Factory::createFactory($package)->getOutputFormats(); + $formats = $this->formatFactory::createFactory($package)->getOutputFormats(); echo "\t" . $package . "\n\t\t" . implode("\n\t\t", $formats) . "\n"; } exit(0); } - public function option_lang(string $k, mixed $v): void + /** + * @return array + */ + public function option_lang(string $k, mixed $v): array { - Config::set_language($v); + return ['language' => $v]; } - public function option_c(string $k, mixed $v): void + /** + * @return array> + */ + public function option_c(string $k, mixed $v): array { if ($k === "C") { - $this->option_css($k, $v); - return; + return $this->option_css($k, $v); } - $this->option_color($k, $v); + return $this->option_color($k, $v); } - public function option_color(string $k, mixed $v): void + /** + * @return array + */ + public function option_color(string $k, mixed $v): array { if (is_array($v)) { trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR); } $val = self::boolval($v); - if (is_bool($val)) { - Config::setColor_output($val); - } else { + if (!is_bool($val)) { trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR); } + return ['color_output' => $val]; } - public function option_css(string $k, mixed $v): void + /** + * @return array> + */ + public function option_css(string $k, mixed $v): array { $styles = []; foreach((array)$v as $key => $val) { @@ -354,17 +451,23 @@ public function option_css(string $k, mixed $v): void $styles[] = $val; } } - Config::set_css($styles); + return ['css' => $styles]; } - public function option_k(string $k, mixed $v): void + /** + * @return array> + */ + public function option_k(string $k, mixed $v): array { - $this->option_packagedir($k, $v); + return $this->option_packagedir($k, $v); } - public function option_packagedir(string $k, mixed $v): void + /** + * @return array> + */ + public function option_packagedir(string $k, mixed $v): array { - $packages = Config::package_dirs(); + $packages = $this->config->package_dirs(); foreach((array)$v as $key => $val) { if ($path = realpath($val)) { if (!in_array($path, $packages)) { @@ -374,17 +477,23 @@ public function option_packagedir(string $k, mixed $v): void v('Invalid path: %s', $val, E_USER_WARNING); } } - Config::set_package_dirs($packages); + return ['package_dirs' => $packages]; } - public function option_x(string $k, mixed $v): void + /** + * @return array + */ + public function option_x(string $k, mixed $v): array { - $this->option_xinclude($k, true); + return $this->option_xinclude($k, true); } - public function option_xinclude(string $k, mixed $v): void + /** + * @return array + */ + public function option_xinclude(string $k, mixed $v): array { - Config::set_process_xincludes(true); + return ['process_xincludes' => true]; } /** @@ -395,17 +504,17 @@ public function option_xinclude(string $k, mixed $v): void */ public function option_version(string $k, mixed $v): never { - $color = Config::phd_info_color(); - $output = Config::phd_info_output(); - fprintf($output, "%s\n", term_color('PhD Version: ' . Config::VERSION, $color)); + $color = $this->config->phd_info_color(); + $output = $this->config->phd_info_output(); + fprintf($output, "%s\n", term_color('PhD Version: ' . $this->config::VERSION, $color)); - $packageList = Config::getSupportedPackages(); + $packageList = $this->config->getSupportedPackages(); foreach ($packageList as $package) { - $version = Format_Factory::createFactory($package)->getPackageVersion(); + $version = $this->formatFactory::createFactory($package)->getPackageVersion(); fprintf($output, "\t%s: %s\n", term_color($package, $color), term_color($version, $color)); } fprintf($output, "%s\n", term_color('PHP Version: ' . phpversion(), $color)); - fprintf($output, "%s\n", term_color(Config::copyright(), $color)); + fprintf($output, "%s\n", term_color($this->config->copyright(), $color)); exit(0); } @@ -416,8 +525,8 @@ public function option_h(string $k, mixed $v): never public function option_help(string $k, mixed $v): never { - echo "PhD version: " .Config::VERSION; - echo "\n" . Config::copyright() . "\n + echo "PhD version: " .$this->config::VERSION; + echo "\n" . $this->config->copyright() . "\n -v --verbose Adjusts the verbosity level -f @@ -459,7 +568,7 @@ public function option_help(string $k, mixed $v): never theme). (default: en) -c --color Enable color output when output is to a terminal - (default: " . (Config::color_output() ? 'true' : 'false') . ") + (default: " . ($this->config->color_output() ? 'true' : 'false') . ") -C --css Link for an external CSS file. -g @@ -487,36 +596,21 @@ public function option_help(string $k, mixed $v): never } /** - * Makes a string into a boolean (i.e. on/off, yes/no, ..) + * Makes one of the following strings into a boolean: + * "on", "off", "yes", "no", "false", "true", "0", "1" * * Returns boolean true/false on success, null on failure - * - * @param mixed $val - * @return ?bool */ - public static function boolval(mixed $val): ?bool + private static function boolval(mixed $val): ?bool { if (!is_string($val)) { return null; } - switch ($val) { - case "on": - case "yes": - case "true": - case "1": - return true; - break; - - case "off": - case "no": - case "false": - case "0": - return false; - break; - - default: - return null; - } + return match ($val) { + "on", "yes", "true", "1" => true, + "off", "no", "false", "0" => false, + default => null + }; } } diff --git a/phpdotnet/phd/Options/Parser.php b/phpdotnet/phd/Options/Parser.php index a2b57722..fde7c76c 100644 --- a/phpdotnet/phd/Options/Parser.php +++ b/phpdotnet/phd/Options/Parser.php @@ -5,7 +5,7 @@ class Options_Parser { private Options_Interface $defaultHandler; - /** @var array */ + /** @var array */ private array $packageHandlers = []; public function __construct( @@ -90,7 +90,10 @@ private function validateOptions(): void { } } - public function getopt() { + /** + * @return array + */ + public function getopt(): array { $this->validateOptions(); $args = getopt($this->getShortOptions(), $this->getLongOptions()); @@ -98,14 +101,20 @@ public function getopt() { trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR); } + $parsedOptions = []; foreach ($args as $k => $v) { $handler = $this->handlerForOption($k); - if (is_callable($handler)) { - call_user_func($handler, $k, $v); - } else { + + if (!is_callable($handler)) { var_dump($k, $v); trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); } + + $retVal = call_user_func($handler, $k, $v); + if (is_array($retVal)) { + $parsedOptions = array_merge($parsedOptions, $retVal); + } } + return $parsedOptions; } } diff --git a/render.php b/render.php index 91390c02..7fa6a2fd 100644 --- a/render.php +++ b/render.php @@ -28,8 +28,13 @@ $packageHandlers[strtolower($package)] = $handler; } } -$optionsParser = new Options_Parser(new Options_Handler, ...$packageHandlers); -$optionsParser->getopt(); +$optionsParser = new Options_Parser( + new Options_Handler(new Config, new Package_Generic_Factory), + ...$packageHandlers +); +$commandLineOptions = $optionsParser->getopt(); + +Config::init($commandLineOptions); /* If no docbook file was passed, die */ if (!is_dir(Config::xml_root()) || !is_file(Config::xml_file())) { From 5a085c0b7a4e337ab991c2cd028c364550d21b12 Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 14 Mar 2024 18:53:21 +0100 Subject: [PATCH 2/5] Minor refactor of files used in tests Inlcude Config with require_once instead of require in Autloader. Define __INSTALLDIR__ only if it is not defined yet in render.php. Include Autoloader and functions.php with require_once instead of require. Remove unnecessary __PHPDIR__ constant, correct path for __INSTALLDIR__ and use that constant in setup.php. --- phpdotnet/phd/Autoloader.php | 2 +- render.php | 8 +++++--- tests/setup.php | 11 +++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/phpdotnet/phd/Autoloader.php b/phpdotnet/phd/Autoloader.php index 884d839f..93d0003c 100644 --- a/phpdotnet/phd/Autoloader.php +++ b/phpdotnet/phd/Autoloader.php @@ -1,7 +1,7 @@ __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR + "lang_dir" => __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR . "phd" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "langs" . DIRECTORY_SEPARATOR, - "package_dirs" => [__PHDDIR__, __INSTALLDIR__], + "package_dirs" => [__INSTALLDIR__], ]); From 6422732be494c028d1da0f56356bb86b9c239cea Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 14 Mar 2024 22:17:20 +0100 Subject: [PATCH 3/5] Remove var_dump from Options Parser --- phpdotnet/phd/Options/Parser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpdotnet/phd/Options/Parser.php b/phpdotnet/phd/Options/Parser.php index fde7c76c..c8763000 100644 --- a/phpdotnet/phd/Options/Parser.php +++ b/phpdotnet/phd/Options/Parser.php @@ -106,7 +106,6 @@ public function getopt(): array { $handler = $this->handlerForOption($k); if (!is_callable($handler)) { - var_dump($k, $v); trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR); } From 462d8dcae83581fb257b49b6482d88bfae47b3f6 Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 14 Mar 2024 22:19:46 +0100 Subject: [PATCH 4/5] Fix inconsistent option flags in default Option Handler --- phpdotnet/phd/Options/Handler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpdotnet/phd/Options/Handler.php b/phpdotnet/phd/Options/Handler.php index 2db56e37..3d0d0255 100644 --- a/phpdotnet/phd/Options/Handler.php +++ b/phpdotnet/phd/Options/Handler.php @@ -23,9 +23,9 @@ public function optionList(): array 'outputfilename:' => 'F:', // The output filename (only useful for bightml/bigpdf) 'partial:' => 'p:', // The ID to render (optionally ignoring its children) 'skip:' => 's:', // The ID to skip (optionally skipping its children too) - 'verbose:' => 'v::', // Adjust the verbosity level + 'verbose::' => 'v::', // Adjust the verbosity level 'list' => 'l', // List supported packages/formats - 'lang::' => 'L:', // Language hint (used by the CHM) + 'lang:' => 'L:', // Language hint (used by the CHM) 'color:' => 'c:', // Use color output if possible 'highlighter:' => 'g:', // Class used as source code highlighter 'version' => 'V', // Print out version information @@ -37,7 +37,7 @@ public function optionList(): array 'saveconfig::' => 'S::', // Save the generated config ? 'quit' => 'Q', // Do not run the render. Use with -S to just save the config. 'memoryindex' => 'M', // Use sqlite in memory rather then file - 'packagedir' => 'k:', // Include path for external packages + 'packagedir:' => 'k:', // Include path for external packages ]; } From 3ac956b5a45e019b7bbe36419712b190a8eaa8c9 Mon Sep 17 00:00:00 2001 From: haszi Date: Thu, 14 Mar 2024 22:20:02 +0100 Subject: [PATCH 5/5] Add default Options Handler tests --- tests/options/default_handler_001.phpt | 48 ++++++++++++++ tests/options/default_handler_002.phpt | 48 ++++++++++++++ tests/options/default_handler_003.phpt | 84 +++++++++++++++++++++++++ tests/options/default_handler_004.phpt | 84 +++++++++++++++++++++++++ tests/options/default_handler_005.phpt | 24 +++++++ tests/options/default_handler_006.phpt | 24 +++++++ tests/options/default_handler_007.phpt | 22 +++++++ tests/options/default_handler_008.phpt | 22 +++++++ tests/options/default_handler_009.phpt | 86 ++++++++++++++++++++++++++ tests/options/default_handler_010.phpt | 86 ++++++++++++++++++++++++++ 10 files changed, 528 insertions(+) create mode 100644 tests/options/default_handler_001.phpt create mode 100644 tests/options/default_handler_002.phpt create mode 100644 tests/options/default_handler_003.phpt create mode 100644 tests/options/default_handler_004.phpt create mode 100644 tests/options/default_handler_005.phpt create mode 100644 tests/options/default_handler_006.phpt create mode 100644 tests/options/default_handler_007.phpt create mode 100644 tests/options/default_handler_008.phpt create mode 100644 tests/options/default_handler_009.phpt create mode 100644 tests/options/default_handler_010.phpt diff --git a/tests/options/default_handler_001.phpt b/tests/options/default_handler_001.phpt new file mode 100644 index 00000000..c6900f8e --- /dev/null +++ b/tests/options/default_handler_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +Default options handler 001 - List packages - short option +--ARGS-- +-l +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Supported packages: + Generic + xhtml + bigxhtml + manpage + IDE + xml + funclist + json + php + phpstub + sqlite + PEAR + xhtml + bigxhtml + php + chm + tocfeed + PHP + xhtml + bigxhtml + php + howto + manpage + pdf + bigpdf + kdevelop + chm + tocfeed + epub + enhancedchm diff --git a/tests/options/default_handler_002.phpt b/tests/options/default_handler_002.phpt new file mode 100644 index 00000000..de29311e --- /dev/null +++ b/tests/options/default_handler_002.phpt @@ -0,0 +1,48 @@ +--TEST-- +Default options handler 002 - List packages - long option +--ARGS-- +--list +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Supported packages: + Generic + xhtml + bigxhtml + manpage + IDE + xml + funclist + json + php + phpstub + sqlite + PEAR + xhtml + bigxhtml + php + chm + tocfeed + PHP + xhtml + bigxhtml + php + howto + manpage + pdf + bigpdf + kdevelop + chm + tocfeed + epub + enhancedchm diff --git a/tests/options/default_handler_003.phpt b/tests/options/default_handler_003.phpt new file mode 100644 index 00000000..a4d8501d --- /dev/null +++ b/tests/options/default_handler_003.phpt @@ -0,0 +1,84 @@ +--TEST-- +Default options handler 003 - Show help - short option +--ARGS-- +-h +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +PhD version: %s +Copyright(c) %d-%d The PHP Documentation Group + + -v + --verbose Adjusts the verbosity level + -f + --format The build format to use + -P + --package The package to use + -I + --noindex Do not index before rendering but load from cache + (default: %s) + -M + --memoryindex Do not save indexing into a file, store it in memory. + (default: %s) + -r + --forceindex Force re-indexing under all circumstances + (default: %s) + -t + --notoc Do not rewrite TOC before rendering but load from + cache (default: %s) + -d + --docbook The Docbook file to render from + -x + --xinclude Process XML Inclusions (XInclude) + (default: %s) + -p + --partial The ID to render, optionally skipping its children + chunks (default to %s; render children) + -s + --skip The ID to skip, optionally skipping its children + chunks (default to %s; skip children) + -l + --list Print out the supported packages and formats + -o + --output The output directory (default: .) + -F filename + --outputfilename filename Filename to use when writing standalone formats + (default: -.) + -L + --lang The language of the source file (used by the CHM + theme). (default: %s) + -c + --color Enable color output when output is to a terminal + (default: %s) + -C + --css Link for an external CSS file. + -g + --highlighter Use custom source code highlighting php class + -V + --version Print the PhD version information + -h + --help This help + -e + --ext The alternative filename extension to use, + including the dot. Use 'false' for no extension. + -S + --saveconfig Save the generated config (default: %s). + + -Q + --quit Don't run the build. Use with --saveconfig to + just save the config. + -k + --packagedir Use an external package directory. + + +Most options can be passed multiple times for greater effect. diff --git a/tests/options/default_handler_004.phpt b/tests/options/default_handler_004.phpt new file mode 100644 index 00000000..a149dde5 --- /dev/null +++ b/tests/options/default_handler_004.phpt @@ -0,0 +1,84 @@ +--TEST-- +Default options handler 004 - Show help - long option +--ARGS-- +--help +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +PhD version: %s +Copyright(c) %d-%d The PHP Documentation Group + + -v + --verbose Adjusts the verbosity level + -f + --format The build format to use + -P + --package The package to use + -I + --noindex Do not index before rendering but load from cache + (default: %s) + -M + --memoryindex Do not save indexing into a file, store it in memory. + (default: %s) + -r + --forceindex Force re-indexing under all circumstances + (default: %s) + -t + --notoc Do not rewrite TOC before rendering but load from + cache (default: %s) + -d + --docbook The Docbook file to render from + -x + --xinclude Process XML Inclusions (XInclude) + (default: %s) + -p + --partial The ID to render, optionally skipping its children + chunks (default to %s; render children) + -s + --skip The ID to skip, optionally skipping its children + chunks (default to %s; skip children) + -l + --list Print out the supported packages and formats + -o + --output The output directory (default: .) + -F filename + --outputfilename filename Filename to use when writing standalone formats + (default: -.) + -L + --lang The language of the source file (used by the CHM + theme). (default: %s) + -c + --color Enable color output when output is to a terminal + (default: %s) + -C + --css Link for an external CSS file. + -g + --highlighter Use custom source code highlighting php class + -V + --version Print the PhD version information + -h + --help This help + -e + --ext The alternative filename extension to use, + including the dot. Use 'false' for no extension. + -S + --saveconfig Save the generated config (default: %s). + + -Q + --quit Don't run the build. Use with --saveconfig to + just save the config. + -k + --packagedir Use an external package directory. + + +Most options can be passed multiple times for greater effect. diff --git a/tests/options/default_handler_005.phpt b/tests/options/default_handler_005.phpt new file mode 100644 index 00000000..7bd54b4d --- /dev/null +++ b/tests/options/default_handler_005.phpt @@ -0,0 +1,24 @@ +--TEST-- +Default options handler 005 - Show version - short option +--ARGS-- +-V +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +%sPhD Version: %s + %sGeneric%s: %s + %sIDE%s: %s + %sPEAR%s: %s + %sPHP%s: %s +%sPHP Version: %s +%sCopyright(c) %d-%d The PHP Documentation Group%s diff --git a/tests/options/default_handler_006.phpt b/tests/options/default_handler_006.phpt new file mode 100644 index 00000000..7c80bfbc --- /dev/null +++ b/tests/options/default_handler_006.phpt @@ -0,0 +1,24 @@ +--TEST-- +Default options handler 006 - Show version - long option +--ARGS-- +--version +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +%sPhD Version: %s + %sGeneric%s: %s + %sIDE%s: %s + %sPEAR%s: %s + %sPHP%s: %s +%sPHP Version: %s +%sCopyright(c) %d-%d The PHP Documentation Group%s diff --git a/tests/options/default_handler_007.phpt b/tests/options/default_handler_007.phpt new file mode 100644 index 00000000..88ee071b --- /dev/null +++ b/tests/options/default_handler_007.phpt @@ -0,0 +1,22 @@ +--TEST-- +Default options handler 007 - Save config (short option) and quit (short option) +--ARGS-- +--docbook tests/options/default_handler_007.phpt -S -Q +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +%s[%d:%d:%d - Heads up ]%s Writing the config file diff --git a/tests/options/default_handler_008.phpt b/tests/options/default_handler_008.phpt new file mode 100644 index 00000000..a38b6f3b --- /dev/null +++ b/tests/options/default_handler_008.phpt @@ -0,0 +1,22 @@ +--TEST-- +Default options handler 008 - Save config (long option) and quit (long option) +--ARGS-- +--docbook tests/options/default_handler_008.phpt --saveconfig --quit +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +%s[%d:%d:%d - Heads up ]%s Writing the config file diff --git a/tests/options/default_handler_009.phpt b/tests/options/default_handler_009.phpt new file mode 100644 index 00000000..5dbf3e94 --- /dev/null +++ b/tests/options/default_handler_009.phpt @@ -0,0 +1,86 @@ +--TEST-- +Default options handler 009 - Long options returned as array +--ARGS-- +--format="xhtml" --noindex --forceindex --notoc --docbook="tests/options/default_handler_009.phpt" --output="tests/options/" --outputfilename="tests/options/default_handler_009.xml" --partial="bookId" --skip="idToSkip" --verbose=E_ALL --lang="en" --color=1 --highlighter="highlighter" --package="PHP" --css="some.css" --xinclude --ext=".html" --memoryindex --packagedir="tests/options/" +--SKIPIF-- + +--FILE-- +getopt(); + +var_dump($commandLineOptions); +?> +--EXPECTF-- +array(20) { + ["output_format"]=> + array(1) { + [0]=> + string(5) "xhtml" + } + ["no_index"]=> + bool(true) + ["force_index"]=> + bool(true) + ["no_toc"]=> + bool(true) + ["xml_root"]=> + string(13) "tests/options" + ["xml_file"]=> + string(38) "tests/options/default_handler_009.phpt" + ["output_dir"]=> + string(14) "tests/options/" + ["output_filename"]=> + string(23) "default_handler_009.xml" + ["render_ids"]=> + array(1) { + ["bookId"]=> + bool(true) + } + ["skip_ids"]=> + array(1) { + ["idToSkip"]=> + bool(true) + } + ["verbose"]=> + int(%d) + ["language"]=> + string(2) "en" + ["color_output"]=> + bool(true) + ["highlighter"]=> + string(11) "highlighter" + ["package"]=> + array(1) { + [0]=> + string(3) "PHP" + } + ["css"]=> + array(1) { + [0]=> + string(8) "some.css" + } + ["process_xincludes"]=> + bool(true) + ["ext"]=> + string(5) ".html" + ["memoryindex"]=> + bool(true) + ["package_dirs"]=> + array(2) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + } +} diff --git a/tests/options/default_handler_010.phpt b/tests/options/default_handler_010.phpt new file mode 100644 index 00000000..311e2309 --- /dev/null +++ b/tests/options/default_handler_010.phpt @@ -0,0 +1,86 @@ +--TEST-- +Default options handler 010 - Short options returned as array +--ARGS-- +-f xhtml -I -r -t -d "tests/options/default_handler_009.phpt" -o "tests/options/" -F "tests/options/default_handler_009.xml" -p bookId -s idToSkip -v="E_ALL" -L en -c 1 -g highlighter -P PHP -C "some.css" -x -e ".html" -M -k="tests/options/" +--SKIPIF-- + +--FILE-- +getopt(); + +var_dump($commandLineOptions); +?> +--EXPECTF-- +array(20) { + ["output_format"]=> + array(1) { + [0]=> + string(5) "xhtml" + } + ["no_index"]=> + bool(true) + ["force_index"]=> + bool(true) + ["no_toc"]=> + bool(true) + ["xml_root"]=> + string(13) "tests/options" + ["xml_file"]=> + string(38) "tests/options/default_handler_009.phpt" + ["output_dir"]=> + string(14) "tests/options/" + ["output_filename"]=> + string(23) "default_handler_009.xml" + ["render_ids"]=> + array(1) { + ["bookId"]=> + bool(true) + } + ["skip_ids"]=> + array(1) { + ["idToSkip"]=> + bool(true) + } + ["verbose"]=> + int(%d) + ["language"]=> + string(2) "en" + ["color_output"]=> + bool(true) + ["highlighter"]=> + string(11) "highlighter" + ["package"]=> + array(1) { + [0]=> + string(3) "PHP" + } + ["css"]=> + array(1) { + [0]=> + string(8) "some.css" + } + ["process_xincludes"]=> + bool(true) + ["ext"]=> + string(5) ".html" + ["memoryindex"]=> + bool(true) + ["package_dirs"]=> + array(2) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + } +}