pax_global_header00006660000000000000000000000064137416372740014530gustar00rootroot0000000000000052 comment=849e0e4c176468dd6e0386fe88a854fcd9ca49da phpunit-cli-parser-1.0.1/000077500000000000000000000000001374163727400152555ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/.github/000077500000000000000000000000001374163727400166155ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/.github/FUNDING.yml000066400000000000000000000000321374163727400204250ustar00rootroot00000000000000github: sebastianbergmann phpunit-cli-parser-1.0.1/.github/workflows/000077500000000000000000000000001374163727400206525ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/.github/workflows/ci.yml000066400000000000000000000052051374163727400217720ustar00rootroot00000000000000# https://help.github.com/en/categories/automating-your-workflow-with-github-actions on: - "pull_request" - "push" name: "CI" jobs: coding-guidelines: name: "Coding Guidelines" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Run friendsofphp/php-cs-fixer" run: "php7.4 ./tools/php-cs-fixer fix --diff-format=udiff --dry-run --show-progress=dots --using-cache=no --verbose" type-checker: name: "Type Checker" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Update dependencies with composer" run: "php7.4 ./tools/composer update --no-ansi --no-interaction --no-progress" - name: "Run vimeo/psalm" run: "php7.4 ./tools/psalm --config=.psalm/config.xml --no-progress --shepherd --show-info=false --stats" backward-compatibility: name: Backward Compatibility runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Fetch tags run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 coverage: none extensions: intl - name: Run roave/backward-compatibility-check run: ./tools/roave-backward-compatibility-check tests: name: "Tests" runs-on: "ubuntu-latest" strategy: fail-fast: false matrix: php-version: - "7.3" - "7.4" - "8.0" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Install PHP with extensions" uses: "shivammathur/setup-php@v1" with: php-version: "${{ matrix.php-version }}" coverage: "pcov" - name: "Cache dependencies installed with composer" uses: "actions/cache@v1" with: path: "~/.composer/cache" key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}" restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install dependencies with composer" run: "./tools/composer update --no-ansi --no-interaction --no-progress" - name: "Run tests with phpunit/phpunit" run: "vendor/bin/phpunit --coverage-clover=coverage.xml" - name: "Send code coverage report to Codecov.io" env: CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" run: "bash <(curl -s https://codecov.io/bash) || true" phpunit-cli-parser-1.0.1/.gitignore000066400000000000000000000001061374163727400172420ustar00rootroot00000000000000/.idea /.php_cs /.php_cs.cache /.phpunit.cache /composer.lock /vendor phpunit-cli-parser-1.0.1/.phive/000077500000000000000000000000001374163727400164465ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/.phive/phars.xml000066400000000000000000000010411374163727400203010ustar00rootroot00000000000000 phpunit-cli-parser-1.0.1/.php_cs.dist000066400000000000000000000173741374163727400175100ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; $finder = PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); return PhpCsFixer\Config::create() ->setFinder($finder) ->setRiskyAllowed(true) ->setRules([ 'align_multiline_comment' => true, 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'operators' => [ '=' => 'align', '=>' => 'align', ], ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'declare', 'do', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', ], ], 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => ['elements' => ['const', 'method', 'property']], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, 'compact_nullable_typehint' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'declare_strict_types' => true, 'dir_constant' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, 'global_namespace_import' => [ 'import_classes' => true, 'import_constants' => true, 'import_functions' => true, ], 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'is_null' => true, 'line_ending' => true, 'list_syntax' => ['syntax' => 'short'], 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, 'magic_constant_casing' => true, 'method_argument_space' => ['ensure_fully_multiline' => true], 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, 'native_constant_invocation' => false, 'native_function_casing' => false, 'native_function_invocation' => false, 'new_with_braces' => false, 'no_alias_functions' => true, 'no_alternative_syntax' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_blank_lines_before_namespace' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_homoglyph_names' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_multiline_whitespace_around_double_arrow' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_short_echo_tag' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => [ 'allow_mixed' => true, ], 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_on_property' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, 'ordered_class_elements' => [ 'order' => [ 'use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public_static', 'property_protected_static', 'property_private_static', 'property_public', 'property_protected', 'property_private', 'method_public_static', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private', 'method_protected_static', 'method_private_static', ], ], 'ordered_imports' => [ 'imports_order' => [ PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CONST, PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_FUNCTION, PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CLASS, ] ], 'ordered_interfaces' => [ 'direction' => 'ascend', 'order' => 'alpha', ], 'phpdoc_add_missing_param_annotation' => false, 'phpdoc_align' => true, 'phpdoc_annotation_without_dot' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], 'phpdoc_types_order' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, 'return_assignment' => true, 'return_type_declaration' => ['space_before' => 'none'], 'self_accessor' => true, 'semicolon_after_instruction' => true, 'set_type_to_cast' => true, 'short_scalar_cast' => true, 'simplified_null_return' => false, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'standardize_not_equals' => true, 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ 'const', 'method', 'property', ], ], 'void_return' => true, 'whitespace_after_comma_in_array' => true, ]); phpunit-cli-parser-1.0.1/.psalm/000077500000000000000000000000001374163727400164475ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/.psalm/baseline.xml000066400000000000000000000003651374163727400207570ustar00rootroot00000000000000 $arg phpunit-cli-parser-1.0.1/.psalm/config.xml000066400000000000000000000007101374163727400204340ustar00rootroot00000000000000 phpunit-cli-parser-1.0.1/ChangeLog.md000066400000000000000000000006341374163727400174310ustar00rootroot00000000000000# ChangeLog All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. ## [1.0.1] - 2020-09-28 ### Changed * Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3` ## [1.0.0] - 2020-08-12 * Initial release [1.0.0]: https://github.com/sebastianbergmann/cli-parser/compare/bb7bb3297957927962b0a3335befe7b66f7462e9...1.0.0 phpunit-cli-parser-1.0.1/LICENSE000066400000000000000000000030161374163727400162620ustar00rootroot00000000000000sebastian/cli-parser Copyright (c) 2020, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. phpunit-cli-parser-1.0.1/README.md000066400000000000000000000007531374163727400165410ustar00rootroot00000000000000# sebastian/cli-parser Library for parsing `$_SERVER['argv']`, extracted from `phpunit/phpunit`. ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): ``` composer require sebastian/cli-parser ``` If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: ``` composer require --dev sebastian/cli-parser ``` phpunit-cli-parser-1.0.1/build.xml000066400000000000000000000021071374163727400170760ustar00rootroot00000000000000 phpunit-cli-parser-1.0.1/composer.json000066400000000000000000000016371374163727400200060ustar00rootroot00000000000000{ "name": "sebastian/cli-parser", "description": "Library for parsing CLI options", "type": "library", "homepage": "https://github.com/sebastianbergmann/cli-parser", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues" }, "prefer-stable": true, "require": { "php": ">=7.3" }, "require-dev": { "phpunit/phpunit": "^9.3" }, "config": { "platform": { "php": "7.3.0" }, "optimize-autoloader": true, "sort-packages": true }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.0-dev" } } } phpunit-cli-parser-1.0.1/infection.json000066400000000000000000000002561374163727400201310ustar00rootroot00000000000000{ "source": { "directories": [ "src" ] }, "mutators": { "@default": true }, "minMsi": 100, "minCoveredMsi": 100 } phpunit-cli-parser-1.0.1/phpunit.xml000066400000000000000000000017241374163727400174720ustar00rootroot00000000000000 tests src phpunit-cli-parser-1.0.1/src/000077500000000000000000000000001374163727400160445ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/src/Parser.php000066400000000000000000000132231374163727400200120ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use function array_map; use function array_merge; use function array_shift; use function array_slice; use function assert; use function count; use function current; use function explode; use function is_array; use function is_int; use function is_string; use function key; use function next; use function preg_replace; use function reset; use function sort; use function strlen; use function strpos; use function strstr; use function substr; final class Parser { /** * @psalm-param list $argv * @psalm-param list $longOptions * * @throws AmbiguousOptionException * @throws RequiredOptionArgumentMissingException * @throws OptionDoesNotAllowArgumentException * @throws UnknownOptionException */ public function parse(array $argv, string $shortOptions, array $longOptions = null): array { if (empty($argv)) { return [[], []]; } $options = []; $nonOptions = []; if ($longOptions) { sort($longOptions); } if (isset($argv[0][0]) && $argv[0][0] !== '-') { array_shift($argv); } reset($argv); $argv = array_map('trim', $argv); while (false !== $arg = current($argv)) { $i = key($argv); assert(is_int($i)); next($argv); if ($arg === '') { continue; } if ($arg === '--') { $nonOptions = array_merge($nonOptions, array_slice($argv, $i + 1)); break; } if ($arg[0] !== '-' || (strlen($arg) > 1 && $arg[1] === '-' && !$longOptions)) { $nonOptions[] = $arg; continue; } if (strlen($arg) > 1 && $arg[1] === '-' && is_array($longOptions)) { $this->parseLongOption( substr($arg, 2), $longOptions, $options, $argv ); } else { $this->parseShortOption( substr($arg, 1), $shortOptions, $options, $argv ); } } return [$options, $nonOptions]; } /** * @throws RequiredOptionArgumentMissingException */ private function parseShortOption(string $arg, string $shortOptions, array &$opts, array &$args): void { $argLength = strlen($arg); for ($i = 0; $i < $argLength; $i++) { $option = $arg[$i]; $optionArgument = null; if ($arg[$i] === ':' || ($spec = strstr($shortOptions, $option)) === false) { throw new UnknownOptionException('-' . $option); } assert(is_string($spec)); if (strlen($spec) > 1 && $spec[1] === ':') { if ($i + 1 < $argLength) { $opts[] = [$option, substr($arg, $i + 1)]; break; } if (!(strlen($spec) > 2 && $spec[2] === ':')) { $optionArgument = current($args); if (!$optionArgument) { throw new RequiredOptionArgumentMissingException('-' . $option); } assert(is_string($optionArgument)); next($args); } } $opts[] = [$option, $optionArgument]; } } /** * @psalm-param list $longOptions * * @throws AmbiguousOptionException * @throws RequiredOptionArgumentMissingException * @throws OptionDoesNotAllowArgumentException * @throws UnknownOptionException */ private function parseLongOption(string $arg, array $longOptions, array &$opts, array &$args): void { $count = count($longOptions); $list = explode('=', $arg); $option = $list[0]; $optionArgument = null; if (count($list) > 1) { $optionArgument = $list[1]; } $optionLength = strlen($option); foreach ($longOptions as $i => $longOption) { $opt_start = substr($longOption, 0, $optionLength); if ($opt_start !== $option) { continue; } $opt_rest = substr($longOption, $optionLength); if ($opt_rest !== '' && $i + 1 < $count && $option[0] !== '=' && strpos($longOptions[$i + 1], $option) === 0) { throw new AmbiguousOptionException('--' . $option); } if (substr($longOption, -1) === '=') { /* @noinspection StrlenInEmptyStringCheckContextInspection */ if (substr($longOption, -2) !== '==' && !strlen((string) $optionArgument)) { if (false === $optionArgument = current($args)) { throw new RequiredOptionArgumentMissingException('--' . $option); } next($args); } } elseif ($optionArgument) { throw new OptionDoesNotAllowArgumentException('--' . $option); } $fullOption = '--' . preg_replace('/={1,2}$/', '', $longOption); $opts[] = [$fullOption, $optionArgument]; return; } throw new UnknownOptionException('--' . $option); } } phpunit-cli-parser-1.0.1/src/exceptions/000077500000000000000000000000001374163727400202255ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/src/exceptions/AmbiguousOptionException.php000066400000000000000000000012011374163727400257330ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use function sprintf; use RuntimeException; final class AmbiguousOptionException extends RuntimeException implements Exception { public function __construct(string $option) { parent::__construct( sprintf( 'Option "%s" is ambiguous', $option ) ); } } phpunit-cli-parser-1.0.1/src/exceptions/Exception.php000066400000000000000000000005541374163727400227000ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use Throwable; interface Exception extends Throwable { } phpunit-cli-parser-1.0.1/src/exceptions/OptionDoesNotAllowArgumentException.php000066400000000000000000000012321374163727400300610ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use function sprintf; use RuntimeException; final class OptionDoesNotAllowArgumentException extends RuntimeException implements Exception { public function __construct(string $option) { parent::__construct( sprintf( 'Option "%s" does not allow an argument', $option ) ); } } phpunit-cli-parser-1.0.1/src/exceptions/RequiredOptionArgumentMissingException.php000066400000000000000000000012431374163727400306230ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use function sprintf; use RuntimeException; final class RequiredOptionArgumentMissingException extends RuntimeException implements Exception { public function __construct(string $option) { parent::__construct( sprintf( 'Required argument for option "%s" is missing', $option ) ); } } phpunit-cli-parser-1.0.1/src/exceptions/UnknownOptionException.php000066400000000000000000000011721374163727400254460ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use function sprintf; use RuntimeException; final class UnknownOptionException extends RuntimeException implements Exception { public function __construct(string $option) { parent::__construct( sprintf( 'Unknown option "%s"', $option ) ); } } phpunit-cli-parser-1.0.1/tests/000077500000000000000000000000001374163727400164175ustar00rootroot00000000000000phpunit-cli-parser-1.0.1/tests/ParserTest.php000066400000000000000000000164461374163727400212370ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CliParser; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\CliParser\Parser * @covers \SebastianBergmann\CliParser\AmbiguousOptionException * @covers \SebastianBergmann\CliParser\OptionDoesNotAllowArgumentException * @covers \SebastianBergmann\CliParser\RequiredOptionArgumentMissingException * @covers \SebastianBergmann\CliParser\UnknownOptionException */ final class ParserTest extends TestCase { public function testParsesShortOptionsWithOptionalValues(): void { $this->assertSame( [ [ [ 'f', null, ], ], [ 'myArgument', ], ], (new Parser)->parse( [ 'command', 'myArgument', '-f', ], 'f::' ) ); } public function testParsesLongOptionsWithValues(): void { $this->assertSame( [ [ ['--exec', null], ['--conf', 'config.xml'], ['--optn', null], ['--optn', 'content-of-o'], ], [ 'parameter-0', 'parameter-1', 'parameter-2', 'parameter-n', ], ], (new Parser)->parse( [ 'command', 'parameter-0', '--exec', 'parameter-1', '--conf', 'config.xml', '--optn', 'parameter-2', '--optn=content-of-o', 'parameter-n', ], '', ['exec', 'conf=', 'optn=='] ) ); } public function testParsesShortongOptionsWithValues(): void { $this->assertSame( [ [ ['x', null], ['c', 'config.xml'], ['o', null], ['o', 'content-of-o'], ], [ 'parameter-0', 'parameter-1', 'parameter-2', 'parameter-n', ], ], (new Parser)->parse( [ 'command', 'parameter-0', '-x', 'parameter-1', '-c', 'config.xml', '-o', 'parameter-2', '-ocontent-of-o', 'parameter-n', ], 'xc:o::' ) ); } public function testParsesLongOptionsAfterArguments(): void { $this->assertSame( [ [ [ '--colors', null, ], ], [ 'myArgument', ], ], (new Parser)->parse( [ 'command', 'myArgument', '--colors', ], '', ['colors=='] ) ); } public function testParsesShortOptionsAfterArguments(): void { $this->assertSame( [ [ [ 'v', null, ], ], [ 'myArgument', ], ], (new Parser)->parse( [ 'command', 'myArgument', '-v', ], 'v' ) ); } public function testReturnsEmptyResultWhenNotOptionsArePassed(): void { $this->assertSame( [ [], [], ], (new Parser)->parse( [], 'v' ) ); } public function testRaisesAnExceptionForUnknownLongOption(): void { $this->expectException(UnknownOptionException::class); $this->expectExceptionMessage('Unknown option "--foo"'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', '--foo', ], '', ['colors'] ); } public function testRaisesAnExceptionForUnknownShortOption(): void { $this->expectException(UnknownOptionException::class); $this->expectExceptionMessage('Unknown option "-v"'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', 'myArgument', '-v', ], '' ); } public function testRaisesAnExceptionWhenRequiredArgumentForLongOptionIsMissing(): void { $this->expectException(RequiredOptionArgumentMissingException::class); $this->expectExceptionMessage('Required argument for option "--foo" is missing'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', '--foo', ], '', ['foo='] ); } public function testRaisesAnExceptionWhenRequiredArgumentForShortOptionIsMissing(): void { $this->expectException(RequiredOptionArgumentMissingException::class); $this->expectExceptionMessage('Required argument for option "-f" is missing'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', 'myArgument', '-f', ], 'f:' ); } public function testRaisesAnExceptionWhenLongOptionIsAmbiguous(): void { $this->expectException(AmbiguousOptionException::class); $this->expectExceptionMessage('Option "--col" is ambiguous'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', '--col', ], '', ['columns', 'colors'] ); } public function testRaisesAnExceptionWhenAnArgumentIsGivenForLongOptionThatDoesNotAllowAnArgument(): void { $this->expectException(OptionDoesNotAllowArgumentException::class); $this->expectExceptionMessage('Option "--foo" does not allow an argument'); /* @noinspection UnusedFunctionResultInspection */ (new Parser)->parse( [ 'command', '--foo=bar', ], '', ['foo'] ); } }