From 1324c2ebf393416331c1c54764ebb3dbb95374cc Mon Sep 17 00:00:00 2001 From: Clay Loveless Date: Thu, 10 Mar 2022 09:55:39 -0500 Subject: [PATCH 01/21] test: update tests and config for PHPUnit 9.5.x --- .gitignore | 1 + composer.json | 4 +- phpunit.xml | 46 ++++++++-------- test/Argument/ValidationTest.php | 20 +++---- test/ArgumentTest.php | 8 +-- test/ArgumentsTest.php | 92 ++++++++++++++++---------------- test/CommandTest.php | 32 +++++------ test/GetoptTest.php | 52 +++++++++--------- test/Help/TemplateTest.php | 6 +-- test/MagicGettersTest.php | 10 ++-- test/Operands/CommonTest.php | 34 ++++++------ test/Operands/HelpTest.php | 12 ++--- test/Operands/MultipleTest.php | 12 ++--- test/Operands/StrictTest.php | 6 +-- test/Operands/ValueTest.php | 8 +-- test/OptionParserTest.php | 20 +++---- test/Options/CommonTest.php | 14 ++--- test/Options/HelpTest.php | 12 ++--- test/Options/NonStrictTest.php | 18 +++---- test/Options/ValueTest.php | 12 ++--- test/Printer.php | 12 ++--- test/Translator/CommonTest.php | 6 +-- 22 files changed, 220 insertions(+), 217 deletions(-) diff --git a/.gitignore b/.gitignore index a6ca990..71c175f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor nbproject _site .idea/ +.phpunit.result.cache diff --git a/composer.json b/composer.json index b06b24e..a08e2bc 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=7.1 || ^8.0", "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^7.5.20", + "phpunit/phpunit": "^9.5.18", "squizlabs/php_codesniffer": "^3.5.8" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml index 838ad22..f25c06e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,24 +1,26 @@ - - - - - - test - - - - - - src - - - + + + + src + + + + + + + + test + + diff --git a/test/Argument/ValidationTest.php b/test/Argument/ValidationTest.php index 2025a15..ff2376e 100644 --- a/test/Argument/ValidationTest.php +++ b/test/Argument/ValidationTest.php @@ -12,14 +12,14 @@ class ValidationTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { GetOpt::setLang('en'); // reset the language parent::tearDown(); } /** @test */ - public function defaultMessageForOption() + public function defaultMessageForOption(): void { $option = Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) ->setValidation('is_numeric'); @@ -31,7 +31,7 @@ public function defaultMessageForOption() } /** @test */ - public function defaultMessageForOperand() + public function defaultMessageForOperand(): void { $operand = Operand::create('alpha') ->setValidation('is_numeric'); @@ -43,7 +43,7 @@ public function defaultMessageForOperand() } /** @test */ - public function defaultMessageForArgument() + public function defaultMessageForArgument(): void { $argument = new Argument(null, 'is_numeric', 'alpha'); @@ -54,7 +54,7 @@ public function defaultMessageForArgument() } /** @test */ - public function usesCustomMessage() + public function usesCustomMessage(): void { $option = Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) ->setValidation('is_numeric', 'alpha has to be numeric'); @@ -66,7 +66,7 @@ public function usesCustomMessage() } /** @test */ - public function usesTranslatedDescriptions() + public function usesTranslatedDescriptions(): void { GetOpt::setLang('de'); $operand = Operand::create('alpha') @@ -79,7 +79,7 @@ public function usesTranslatedDescriptions() } /** @test */ - public function providesValueAsSecondReplacement() + public function providesValueAsSecondReplacement(): void { $option = Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) ->setValidation('is_numeric', '%s %s'); @@ -91,7 +91,7 @@ public function providesValueAsSecondReplacement() } /** @test */ - public function usesCallbackToGetMessage() + public function usesCallbackToGetMessage(): void { $option = Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) ->setValidation('is_numeric', function () { @@ -105,7 +105,7 @@ public function usesCallbackToGetMessage() } /** @test */ - public function providesOptionAndValue() + public function providesOptionAndValue(): void { $option = Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT); $option->setValidation('is_numeric', function (Describable $object, $value) use ($option) { @@ -121,7 +121,7 @@ public function providesOptionAndValue() } /** @test */ - public function providesOperandAndValue() + public function providesOperandAndValue(): void { $operand = Operand::create('alpha'); $operand->setValidation('is_numeric', function (Describable $object, $value) use ($operand) { diff --git a/test/ArgumentTest.php b/test/ArgumentTest.php index 33076f1..6099db8 100644 --- a/test/ArgumentTest.php +++ b/test/ArgumentTest.php @@ -8,7 +8,7 @@ class ArgumentTest extends TestCase { /** @test */ - public function constructor() + public function constructor(): void { $argument1 = new Argument(); $argument2 = new Argument(10); @@ -17,7 +17,7 @@ public function constructor() } /** @test */ - public function setDefaultValueNotScalar() + public function setDefaultValueNotScalar(): void { self::expectException(\InvalidArgumentException::class); $argument = new Argument(); @@ -25,7 +25,7 @@ public function setDefaultValueNotScalar() } /** @test */ - public function validates() + public function validates(): void { $test = $this; $argument = new Argument(); @@ -40,7 +40,7 @@ function ($arg) use ($test, $argument) { } /** @test */ - public function falsyDefaultValue() + public function falsyDefaultValue(): void { $argument = new Argument(''); diff --git a/test/ArgumentsTest.php b/test/ArgumentsTest.php index 2a3beff..d9b6a19 100644 --- a/test/ArgumentsTest.php +++ b/test/ArgumentsTest.php @@ -17,13 +17,13 @@ class ArgumentsTest extends TestCase /** @var GetOpt */ protected $getopt; - protected function setUp() + protected function setUp(): void { $this->getopt = new GetOpt(); } /** @test */ - public function parseNoOptions() + public function parseNoOptions(): void { $this->getopt->process(Arguments::fromString('something')); @@ -34,7 +34,7 @@ public function parseNoOptions() } /** @test */ - public function parseUnknownOption() + public function parseUnknownOption(): void { self::expectException(Unexpected::class); $this->getopt->addOption(new Option('a', null)); @@ -43,7 +43,7 @@ public function parseUnknownOption() } /** @test */ - public function unknownLongOption() + public function unknownLongOption(): void { self::expectException(Unexpected::class); $this->getopt->addOption(new Option('a', 'alpha')); @@ -52,7 +52,7 @@ public function unknownLongOption() } /** @test */ - public function parseRequiredArgumentMissing() + public function parseRequiredArgumentMissing(): void { self::expectException(Missing::class); $this->getopt->addOption(new Option('a', null, GetOpt::REQUIRED_ARGUMENT)); @@ -61,7 +61,7 @@ public function parseRequiredArgumentMissing() } /** @test */ - public function parseMultipleOptionsWithOneHyphen() + public function parseMultipleOptionsWithOneHyphen(): void { $this->getopt->addOptions([ new Option('a'), @@ -76,7 +76,7 @@ public function parseMultipleOptionsWithOneHyphen() } /** @test */ - public function parseCumulativeOption() + public function parseCumulativeOption(): void { $this->getopt->addOptions([ new Option('a'), @@ -91,7 +91,7 @@ public function parseCumulativeOption() } /** @test */ - public function parseCumulativeOptionShort() + public function parseCumulativeOptionShort(): void { $this->getopt->addOptions([ new Option('a'), @@ -106,7 +106,7 @@ public function parseCumulativeOptionShort() } /** @test */ - public function parseShortOptionWithArgument() + public function parseShortOptionWithArgument(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -119,7 +119,7 @@ public function parseShortOptionWithArgument() } /** @test */ - public function parseZeroArgument() + public function parseZeroArgument(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -132,7 +132,7 @@ public function parseZeroArgument() } /** @test */ - public function parseNumericOption() + public function parseNumericOption(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT), @@ -147,7 +147,7 @@ public function parseNumericOption() } /** @test */ - public function parseCollapsedShortOptionsRequiredArgumentMissing() + public function parseCollapsedShortOptionsRequiredArgumentMissing(): void { self::expectException(Missing::class); $this->getopt->addOptions([ @@ -158,7 +158,7 @@ public function parseCollapsedShortOptionsRequiredArgumentMissing() } /** @test */ - public function parseCollapsedShortOptionsWithArgument() + public function parseCollapsedShortOptionsWithArgument(): void { $this->getopt->addOptions([ new Option('a', null), @@ -172,7 +172,7 @@ public function parseCollapsedShortOptionsWithArgument() } /** @test */ - public function parseNoArgumentOptionAndOperand() + public function parseNoArgumentOptionAndOperand(): void { $this->getopt->addOptions([ new Option('a', null), @@ -187,7 +187,7 @@ public function parseNoArgumentOptionAndOperand() } /** @test */ - public function parsedRequiredArgumentWithNoSpace() + public function parsedRequiredArgumentWithNoSpace(): void { $this->getopt->addOptions([ new Option('p', null, GetOpt::REQUIRED_ARGUMENT) @@ -197,7 +197,7 @@ public function parsedRequiredArgumentWithNoSpace() self::assertSame('password', $options['p']); } /** @test */ - public function parseCollapsedRequiredArgumentWithNoSpace() + public function parseCollapsedRequiredArgumentWithNoSpace(): void { $this->getopt->addOptions([ new Option('v', null), @@ -210,7 +210,7 @@ public function parseCollapsedRequiredArgumentWithNoSpace() } /** @test */ - public function parseOperandsOnly() + public function parseOperandsOnly(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT), @@ -226,7 +226,7 @@ public function parseOperandsOnly() } /** @test */ - public function parseLongOptionWithoutArgument() + public function parseLongOptionWithoutArgument(): void { $this->getopt->addOptions([ new Option('o', 'option', GetOpt::OPTIONAL_ARGUMENT) @@ -238,7 +238,7 @@ public function parseLongOptionWithoutArgument() } /** @test */ - public function parseLongOptionWithoutArgumentAndOperand() + public function parseLongOptionWithoutArgumentAndOperand(): void { $this->getopt->addOptions([ new Option('o', 'option', GetOpt::NO_ARGUMENT) @@ -253,7 +253,7 @@ public function parseLongOptionWithoutArgumentAndOperand() } /** @test */ - public function parseLongOptionWithArgument() + public function parseLongOptionWithArgument(): void { $this->getopt->addOptions([ new Option('o', 'option', GetOpt::OPTIONAL_ARGUMENT) @@ -266,7 +266,7 @@ public function parseLongOptionWithArgument() } /** @test */ - public function parseLongOptionWithEqualsSignAndArgument() + public function parseLongOptionWithEqualsSignAndArgument(): void { $this->getopt->addOptions([ new Option('o', 'option', GetOpt::OPTIONAL_ARGUMENT) @@ -281,7 +281,7 @@ public function parseLongOptionWithEqualsSignAndArgument() } /** @test */ - public function parseLongOptionWithValueStartingWithHyphen() + public function parseLongOptionWithValueStartingWithHyphen(): void { $this->getopt->addOptions([ new Option('o', 'option', GetOpt::REQUIRED_ARGUMENT) @@ -293,7 +293,7 @@ public function parseLongOptionWithValueStartingWithHyphen() } /** @test */ - public function parseValueStartingWithHypenRequired() + public function parseValueStartingWithHypenRequired(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT), @@ -305,7 +305,7 @@ public function parseValueStartingWithHypenRequired() } /** @test */ - public function parseNoValueStartingWithHyphenOptional() + public function parseNoValueStartingWithHyphenOptional(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::OPTIONAL_ARGUMENT), @@ -319,7 +319,7 @@ public function parseNoValueStartingWithHyphenOptional() } /** @test */ - public function parseOptionWithDefaultValue() + public function parseOptionWithDefaultValue(): void { $optionA = new Option('a', null, GetOpt::REQUIRED_ARGUMENT); $optionA->setArgument(new Argument(10)); @@ -335,7 +335,7 @@ public function parseOptionWithDefaultValue() } /** @test */ - public function multipleArgumentOptions() + public function multipleArgumentOptions(): void { $this->getopt->addOption(new Option('a', null, GetOpt::MULTIPLE_ARGUMENT)); @@ -345,7 +345,7 @@ public function multipleArgumentOptions() } /** @test */ - public function doubleHyphenNotInOperands() + public function doubleHyphenNotInOperands(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -362,7 +362,7 @@ public function doubleHyphenNotInOperands() } /** @test */ - public function singleHyphenValue() + public function singleHyphenValue(): void { $this->getopt->addOptions([ new Option('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) @@ -384,7 +384,7 @@ public function singleHyphenValue() } /** @test */ - public function singleHyphenOperand() + public function singleHyphenOperand(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -399,7 +399,7 @@ public function singleHyphenOperand() } /** @test */ - public function optionsAfterOperands() + public function optionsAfterOperands(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT), @@ -416,7 +416,7 @@ public function optionsAfterOperands() } /** @test */ - public function emptyOperandsAndOptionsWithString() + public function emptyOperandsAndOptionsWithString(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -429,7 +429,7 @@ public function emptyOperandsAndOptionsWithString() } /** @test */ - public function emptyOperandsAndOptionsWithArray() + public function emptyOperandsAndOptionsWithArray(): void { $this->getopt->addOptions([ new Option('a', null, GetOpt::REQUIRED_ARGUMENT) @@ -447,7 +447,7 @@ public function emptyOperandsAndOptionsWithArray() } /** @test */ - public function spaceOperand() + public function spaceOperand(): void { $this->getopt->addOptions([]); @@ -457,7 +457,7 @@ public function spaceOperand() } /** @test */ - public function parseWithArgumentValidation() + public function parseWithArgumentValidation(): void { $validation = 'is_numeric'; $optionA = new Option('a', null, GetOpt::OPTIONAL_ARGUMENT); @@ -476,7 +476,7 @@ public function parseWithArgumentValidation() } /** @test */ - public function parseInvalidArgument() + public function parseInvalidArgument(): void { self::expectException(Invalid::class); $validation = 'is_numeric'; @@ -487,7 +487,7 @@ public function parseInvalidArgument() } /** @test */ - public function stringWithSingleQuotes() + public function stringWithSingleQuotes(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -500,7 +500,7 @@ public function stringWithSingleQuotes() } /** @test */ - public function stringWithDoubleQuotes() + public function stringWithDoubleQuotes(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -513,7 +513,7 @@ public function stringWithDoubleQuotes() } /** @test */ - public function singleQuotesInString() + public function singleQuotesInString(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -526,7 +526,7 @@ public function singleQuotesInString() } /** @test */ - public function doubleQuotesInString() + public function doubleQuotesInString(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -539,7 +539,7 @@ public function doubleQuotesInString() } /** @test */ - public function quoteConcatenation() + public function quoteConcatenation(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -554,7 +554,7 @@ public function quoteConcatenation() } /** @test */ - public function quoteEscapingDoubleQuote() + public function quoteEscapingDoubleQuote(): void { $this->getopt->process('-- "this \\" is a double quote"'); @@ -562,7 +562,7 @@ public function quoteEscapingDoubleQuote() } /** @test */ - public function quoteEscapingSingleQuote() + public function quoteEscapingSingleQuote(): void { $this->getopt->process("-- 'this \\' is a single quote'"); @@ -570,7 +570,7 @@ public function quoteEscapingSingleQuote() } /** @test */ - public function linefeedAsSeparator() + public function linefeedAsSeparator(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -583,7 +583,7 @@ public function linefeedAsSeparator() } /** @test */ - public function tabAsSeparator() + public function tabAsSeparator(): void { $this->getopt->addOptions([ new Option('a', 'optA', GetOpt::REQUIRED_ARGUMENT), @@ -596,7 +596,7 @@ public function tabAsSeparator() } /** @test */ - public function explictArguments() + public function explictArguments(): void { $getopt = $this->getopt; $this->getopt->addOptions([ @@ -611,7 +611,7 @@ public function explictArguments() } /** @test */ - public function usingCommand() + public function usingCommand(): void { $cmd = new Command('test', 'var_dump', [ new Option('a', 'alpha') diff --git a/test/CommandTest.php b/test/CommandTest.php index 7b6fa67..f9c24f7 100644 --- a/test/CommandTest.php +++ b/test/CommandTest.php @@ -13,7 +13,7 @@ class CommandTest extends TestCase protected $command; protected $options = []; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -29,7 +29,7 @@ protected function setUp() } /** @test */ - public function constructorSavesName() + public function constructorSavesName(): void { self::assertSame('the-name', $this->command->getName()); } @@ -37,7 +37,7 @@ public function constructorSavesName() /** @dataProvider dataNamesNotAllowed * @param string $name * @test */ - public function namesNotAllowed($name) + public function namesNotAllowed($name): void { self::expectException(\InvalidArgumentException::class); new Command($name, '', null); @@ -53,19 +53,19 @@ public function dataNamesNotAllowed() } /** @test */ - public function constructorSavesHandler() + public function constructorSavesHandler(): void { self::assertSame([ '\PDO', 'getAvailableDrivers' ], $this->command->getHandler()); } /** @test */ - public function constructorSavesOptions() + public function constructorSavesOptions(): void { self::assertSame($this->options, $this->command->getOptions()); } /** @test */ - public function addOptionsAppendsOptions() + public function addOptionsAppendsOptions(): void { $optionC = new Option('c', 'optc'); $this->command->addOptions([ $optionC ]); @@ -74,7 +74,7 @@ public function addOptionsAppendsOptions() } /** @test */ - public function commandWithConflictingOptionsFailsToAdd() + public function commandWithConflictingOptionsFailsToAdd(): void { $getOpt = new GetOpt([Option::create('v', 'verbose')]); $command = new Command('foo', 'var_dump'); @@ -87,7 +87,7 @@ public function commandWithConflictingOptionsFailsToAdd() } /** @test */ - public function operandsHaveToFollowCommands() + public function operandsHaveToFollowCommands(): void { $getOpt = new GetOpt([Option::create(null, 'version')]); $command = new Command('bar', 'var_dump'); @@ -100,7 +100,7 @@ public function operandsHaveToFollowCommands() } /** @test */ - public function shortDescriptionUsedForDescription() + public function shortDescriptionUsedForDescription(): void { $command = new Command('test', 'var_dump'); @@ -110,7 +110,7 @@ public function shortDescriptionUsedForDescription() } /** @test */ - public function descriptionUsedForShortDescription() + public function descriptionUsedForShortDescription(): void { $command = new Command('test', 'var_dump'); @@ -120,7 +120,7 @@ public function descriptionUsedForShortDescription() } /** @test */ - public function getHelpForExecutedCommand() + public function getHelpForExecutedCommand(): void { $longDescription = 'This is a very long description.' . PHP_EOL . 'It also may have line breaks.'; $getopt = new GetOpt(); @@ -146,7 +146,7 @@ public function getHelpForExecutedCommand() } /** @test */ - public function getHelpForCommands() + public function getHelpForCommands(): void { $cmd1 = Command::create('help', 'var_dump')->setDescription('Shows help for a command'); $cmd2 = Command::create('run:tests', 'var_dump')->setDescription('Executes the tests'); @@ -170,7 +170,7 @@ public function getHelpForCommands() } /** @test */ - public function tooLongShortDescription() + public function tooLongShortDescription(): void { defined('COLUMNS') || define('COLUMNS', 90); $getopt = new GetOpt([ @@ -199,7 +199,7 @@ public function tooLongShortDescription() } /** @test */ - public function commandsWithSpaces() + public function commandsWithSpaces(): void { $getOpt = new GetOpt(); $command = Command::create('import reviews', 'var_dump'); @@ -211,7 +211,7 @@ public function commandsWithSpaces() } /** @test */ - public function singleWordCommandHavePrecedence() + public function singleWordCommandHavePrecedence(): void { $getOpt = new GetOpt(); $import = Command::create('import', 'var_dump'); @@ -225,7 +225,7 @@ public function singleWordCommandHavePrecedence() } /** @test */ - public function commandCannotBeDividedByOptions() + public function commandCannotBeDividedByOptions(): void { $getOpt = new GetOpt([Option::create(null, 'version')]); $command = Command::create('import reviews', 'var_dump'); diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 646f8ba..4bc1a8a 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -11,14 +11,14 @@ class GetoptTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { GetOpt::setLang('en'); parent::tearDown(); } /** @test */ - public function addOptions() + public function addOptions(): void { $getopt = new GetOpt(); $getopt->addOptions('a:'); @@ -36,7 +36,7 @@ public function addOptions() } /** @test */ - public function addOptionsChooseShortOrLongAutomatically() + public function addOptionsChooseShortOrLongAutomatically(): void { $getopt = new GetOpt(); $getopt->addOptions([ @@ -50,7 +50,7 @@ public function addOptionsChooseShortOrLongAutomatically() } /** @test */ - public function addOptionsUseDefaultArgumentType() + public function addOptionsUseDefaultArgumentType(): void { $getopt = new GetOpt(null, [ GetOpt::SETTING_DEFAULT_MODE => GetOpt::REQUIRED_ARGUMENT @@ -65,7 +65,7 @@ public function addOptionsUseDefaultArgumentType() } /** @test */ - public function addOptionsFailsOnInvalidArgument() + public function addOptionsFailsOnInvalidArgument(): void { self::expectException(\InvalidArgumentException::class); $getopt = new GetOpt(null); @@ -73,7 +73,7 @@ public function addOptionsFailsOnInvalidArgument() } /** @test */ - public function changeModeAfterwards() + public function changeModeAfterwards(): void { $getopt = new GetOpt([ [ 'a', null, GetOpt::REQUIRED_ARGUMENT ] @@ -107,7 +107,7 @@ public function provideConflictOptions() * @test * @param array $options */ - public function addOptionsFailsOnConflict($options) + public function addOptionsFailsOnConflict($options): void { self::expectException(\InvalidArgumentException::class); $getopt = new GetOpt(); @@ -115,7 +115,7 @@ public function addOptionsFailsOnConflict($options) } /** @test */ - public function parseUsesGlobalArgvWhenNoneGiven() + public function parseUsesGlobalArgvWhenNoneGiven(): void { $_SERVER['argv'] = [ 'foo.php', '-a' ]; @@ -125,7 +125,7 @@ public function parseUsesGlobalArgvWhenNoneGiven() } /** @test */ - public function accessMethods() + public function accessMethods(): void { $getopt = new GetOpt('a'); $getopt->process('-a foo'); @@ -142,7 +142,7 @@ public function accessMethods() } /** @test */ - public function countable() + public function countable(): void { $getopt = new GetOpt([ new Option('a', 'alpha'), @@ -154,7 +154,7 @@ public function countable() } /** @test */ - public function arrayAccess() + public function arrayAccess(): void { $getopt = new GetOpt('q'); $getopt->process('-q'); @@ -162,7 +162,7 @@ public function arrayAccess() } /** @test */ - public function iterable() + public function iterable(): void { $getopt = new GetOpt([ [ null, 'alpha', GetOpt::NO_ARGUMENT ], @@ -177,7 +177,7 @@ public function iterable() } /** @test */ - public function iteratesOverEmptyStrings() + public function iteratesOverEmptyStrings(): void { $getopt = new GetOpt([ [ 'a', 'alpha' , GetOpt::REQUIRED_ARGUMENT ] @@ -191,7 +191,7 @@ public function iteratesOverEmptyStrings() } /** @test */ - public function helpTextWithCustomScriptName() + public function helpTextWithCustomScriptName(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_SCRIPT_NAME, 'test'); @@ -202,7 +202,7 @@ public function helpTextWithCustomScriptName() } /** @test */ - public function helpTextWithDescription() + public function helpTextWithDescription(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_SCRIPT_NAME, 'test'); @@ -219,7 +219,7 @@ public function helpTextWithDescription() } /** @test */ - public function throwsWithInvalidParameter() + public function throwsWithInvalidParameter(): void { self::expectException(\InvalidArgumentException::class); $getopt = new GetOpt(); @@ -228,7 +228,7 @@ public function throwsWithInvalidParameter() } /** @test */ - public function addOptionByString() + public function addOptionByString(): void { $getopt = new GetOpt(); $getopt->addOption('c'); @@ -237,7 +237,7 @@ public function addOptionByString() } /** @test */ - public function throwsForUnparsableString() + public function throwsForUnparsableString(): void { self::expectException(\InvalidArgumentException::class); $getopt = new GetOpt(); @@ -246,7 +246,7 @@ public function throwsForUnparsableString() } /** @test */ - public function throwsForInvalidParameter() + public function throwsForInvalidParameter(): void { self::expectException(\InvalidArgumentException::class); $getopt = new GetOpt(); @@ -255,7 +255,7 @@ public function throwsForInvalidParameter() } /** @test */ - public function issetArrayAccess() + public function issetArrayAccess(): void { $getopt = new GetOpt(); $getopt->addOption('a'); @@ -267,7 +267,7 @@ public function issetArrayAccess() } /** @test */ - public function restirctsArraySet() + public function restirctsArraySet(): void { self::expectException(\LogicException::class); $getopt = new GetOpt(); @@ -276,7 +276,7 @@ public function restirctsArraySet() } /** @test */ - public function restrictsArrayUnset() + public function restrictsArrayUnset(): void { self::expectException(\LogicException::class); $getopt = new GetOpt(); @@ -287,7 +287,7 @@ public function restrictsArrayUnset() } /** @test */ - public function addCommandWithConflictingOptions() + public function addCommandWithConflictingOptions(): void { self::expectException(\InvalidArgumentException::class); @@ -301,7 +301,7 @@ public function addCommandWithConflictingOptions() } /** @test */ - public function getCommandByName() + public function getCommandByName(): void { $cmd1 = new Command('help', 'var_dump'); $cmd2 = new Command('test', 'var_dump'); @@ -315,7 +315,7 @@ public function getCommandByName() } /** @test */ - public function setHelpLangToDe() + public function setHelpLangToDe(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_SCRIPT_NAME, 'test'); @@ -333,7 +333,7 @@ public function setHelpLangToDe() } /** @test */ - public function returnsFalseWhenFileDoesNotExist() + public function returnsFalseWhenFileDoesNotExist(): void { $getopt = new GetOpt(); diff --git a/test/Help/TemplateTest.php b/test/Help/TemplateTest.php index bdeb6e5..41106c3 100644 --- a/test/Help/TemplateTest.php +++ b/test/Help/TemplateTest.php @@ -11,7 +11,7 @@ class TemplateTest extends TestCase { /** @test */ - public function rendersUsageTemplate() + public function rendersUsageTemplate(): void { $getOpt = new GetOpt(); $scriptName = $getOpt->get(GetOpt::SETTING_SCRIPT_NAME); @@ -25,7 +25,7 @@ public function rendersUsageTemplate() } /** @test */ - public function rendersOptionsTemplate() + public function rendersOptionsTemplate(): void { $getOpt = new GetOpt([ Option::create('a', 'alpha', GetOpt::OPTIONAL_ARGUMENT), @@ -47,7 +47,7 @@ public function rendersOptionsTemplate() } /** @test */ - public function rendersCommandsTemplate() + public function rendersCommandsTemplate(): void { $getOpt = new GetOpt(); $getOpt->addCommand(Command::create('test', 'var_dump')->setDescription('Run this tests')); diff --git a/test/MagicGettersTest.php b/test/MagicGettersTest.php index 2b130fb..1a1002f 100644 --- a/test/MagicGettersTest.php +++ b/test/MagicGettersTest.php @@ -14,7 +14,7 @@ class MagicGettersTest extends TestCase { /** @dataProvider provideGetOptAttributes * @test */ - public function getOptUsesMagicGetters($getOpt, $attribute, $expected) + public function getOptUsesMagicGetters($getOpt, $attribute, $expected): void { $result = $getOpt->{$attribute}; @@ -49,7 +49,7 @@ public function provideGetOptAttributes() /** @dataProvider provideCommandAttributes * @test */ - public function commandUsesMagicGetters($command, $attribute, $expected) + public function commandUsesMagicGetters($command, $attribute, $expected): void { $result = $command->{$attribute}; @@ -74,7 +74,7 @@ public function provideCommandAttributes() /** @dataProvider provideArgumentAttributes * @test */ - public function argumentUsesMagicGetters($argument, $attribute, $expected) + public function argumentUsesMagicGetters($argument, $attribute, $expected): void { $result = $argument->{$attribute}; @@ -93,7 +93,7 @@ public function provideArgumentAttributes() /** @dataProvider provideOperandAttributes * @test */ - public function operandUsesMagicGetters($operand, $attribute, $expected) + public function operandUsesMagicGetters($operand, $attribute, $expected): void { $result = $operand->{$attribute}; @@ -113,7 +113,7 @@ public function provideOperandAttributes() /** @dataProvider provideOptionAttributes * @test */ - public function optionUsesMagicGetters($option, $attribute, $expected) + public function optionUsesMagicGetters($option, $attribute, $expected): void { $result = $option->{$attribute}; diff --git a/test/Operands/CommonTest.php b/test/Operands/CommonTest.php index 7e8540b..08deb9e 100644 --- a/test/Operands/CommonTest.php +++ b/test/Operands/CommonTest.php @@ -12,7 +12,7 @@ class CommonTest extends TestCase { /** @test */ - public function operandsAreResetted() + public function operandsAreResetted(): void { $getopt = new GetOpt(); $getopt->process('"any operand"'); @@ -23,7 +23,7 @@ public function operandsAreResetted() } /** @test */ - public function addOperands() + public function addOperands(): void { $operand1 = new Operand('op1'); $operand2 = new Operand('op2'); @@ -37,7 +37,7 @@ public function addOperands() } /** @test */ - public function operandValidation() + public function operandValidation(): void { $operand = Operand::create('op1') ->setValidation(function ($value) { @@ -52,7 +52,7 @@ public function operandValidation() } /** @test */ - public function optionalOperand() + public function optionalOperand(): void { $operand = new Operand('op1', Operand::OPTIONAL); // false is default @@ -64,7 +64,7 @@ public function optionalOperand() } /** @test */ - public function requiredOperand() + public function requiredOperand(): void { $operand = new Operand('op1', Operand::REQUIRED); @@ -76,7 +76,7 @@ public function requiredOperand() } /** @test */ - public function getOperandByName() + public function getOperandByName(): void { $operand = new Operand('op1'); @@ -88,7 +88,7 @@ public function getOperandByName() } /** @test */ - public function defaultValue() + public function defaultValue(): void { $operand = Operand::create('op1') ->setDefaultValue(42); @@ -101,7 +101,7 @@ public function defaultValue() } /** @test */ - public function allPreviousOperandsGetRequiredToo() + public function allPreviousOperandsGetRequiredToo(): void { $operand1 = new Operand('op1', Operand::OPTIONAL); $operand2 = new Operand('op2', Operand::REQUIRED); @@ -113,7 +113,7 @@ public function allPreviousOperandsGetRequiredToo() } /** @test */ - public function commandsCanHaveOperands() + public function commandsCanHaveOperands(): void { $operand = new Operand('op1'); $command = new Command('command1', 'var_dump'); @@ -123,7 +123,7 @@ public function commandsCanHaveOperands() } /** @test */ - public function commandWithOperand() + public function commandWithOperand(): void { $getopt = new GetOpt(); $command = new Command('command', 'var_dump'); @@ -137,7 +137,7 @@ public function commandWithOperand() } /** @test */ - public function returnsNullForUnknownOperands() + public function returnsNullForUnknownOperands(): void { $getopt = new GetOpt(); @@ -147,7 +147,7 @@ public function returnsNullForUnknownOperands() } /** @test */ - public function requireMakesRequired() + public function requireMakesRequired(): void { $operand = new Operand('op1'); @@ -157,7 +157,7 @@ public function requireMakesRequired() } /** @test */ - public function requireFalse() + public function requireFalse(): void { $operand = new Operand('op1', Operand::REQUIRED); @@ -167,7 +167,7 @@ public function requireFalse() } /** @test */ - public function requireDoesNotMakeAnOperandMultiple() + public function requireDoesNotMakeAnOperandMultiple(): void { $operand = new Operand('op1'); @@ -179,7 +179,7 @@ public function requireDoesNotMakeAnOperandMultiple() } /** @test */ - public function multipleMakesMultiple() + public function multipleMakesMultiple(): void { $operand = new Operand('op1'); @@ -189,7 +189,7 @@ public function multipleMakesMultiple() } /** @test */ - public function multipleFalse() + public function multipleFalse(): void { $operand = new Operand('op1', Operand::MULTIPLE); @@ -199,7 +199,7 @@ public function multipleFalse() } /** @test */ - public function requiredMultipleThrowsMissing() + public function requiredMultipleThrowsMissing(): void { $operand = new Operand('port'); $operand->multiple(true); diff --git a/test/Operands/HelpTest.php b/test/Operands/HelpTest.php index 3947e04..eaba7e5 100644 --- a/test/Operands/HelpTest.php +++ b/test/Operands/HelpTest.php @@ -12,7 +12,7 @@ class HelpTest extends TestCase { /** @test */ - public function helpContainsOperandNames() + public function helpContainsOperandNames(): void { $operand1 = new Operand('op1', true); $operand2 = new Operand('op2', false); @@ -28,7 +28,7 @@ public function helpContainsOperandNames() } /** @test */ - public function helpCommandDefinesOperands() + public function helpCommandDefinesOperands(): void { $operand1 = new Operand('op1', true); $operand2 = new Operand('op2', false); @@ -52,7 +52,7 @@ public function helpCommandDefinesOperands() } /** @test */ - public function helpTextForMultiple() + public function helpTextForMultiple(): void { $operand = new Operand('op1', Operand::MULTIPLE); $script = $_SERVER['PHP_SELF']; @@ -67,7 +67,7 @@ public function helpTextForMultiple() } /** @test */ - public function helpTextForRequiredMultiple() + public function helpTextForRequiredMultiple(): void { $operand = new Operand('op1', Operand::MULTIPLE + Operand::REQUIRED); $script = $_SERVER['PHP_SELF']; @@ -82,7 +82,7 @@ public function helpTextForRequiredMultiple() } /** @test */ - public function showsDescriptionsBeforeOptions() + public function showsDescriptionsBeforeOptions(): void { $script = $_SERVER['PHP_SELF']; $getOpt = new GetOpt(null, [GetOpt::SETTING_STRICT_OPERANDS => true]); @@ -105,7 +105,7 @@ public function showsDescriptionsBeforeOptions() } /** @test */ - public function hidesDescriptionsIfRequested() + public function hidesDescriptionsIfRequested(): void { $script = $_SERVER['PHP_SELF']; $getOpt = new GetOpt(null, [GetOpt::SETTING_STRICT_OPERANDS => true]); diff --git a/test/Operands/MultipleTest.php b/test/Operands/MultipleTest.php index 14bb3ea..db3a43d 100644 --- a/test/Operands/MultipleTest.php +++ b/test/Operands/MultipleTest.php @@ -11,7 +11,7 @@ class MultipleTest extends TestCase { /** @test */ - public function valueForMultiple() + public function valueForMultiple(): void { $operand1 = new Operand('op1', Operand::OPTIONAL); $operand2 = new Operand('op2', Operand::MULTIPLE); @@ -26,7 +26,7 @@ public function valueForMultiple() } /** @test */ - public function defaultValueForMultiple() + public function defaultValueForMultiple(): void { $operand = Operand::create('op1', Operand::MULTIPLE) ->setDefaultValue(42); @@ -39,7 +39,7 @@ public function defaultValueForMultiple() } /** @test */ - public function requiredMultiple() + public function requiredMultiple(): void { $operand = new Operand('op1', true, null, null, true); @@ -51,7 +51,7 @@ public function requiredMultiple() } /** @test */ - public function requiredMultipleNotToThrow() + public function requiredMultipleNotToThrow(): void { $operand = new Operand('op1', Operand::REQUIRED + Operand::MULTIPLE); @@ -63,7 +63,7 @@ public function requiredMultipleNotToThrow() } /** @test */ - public function validationOfMultiple() + public function validationOfMultiple(): void { $operand1 = Operand::create('op1', Operand::MULTIPLE) ->setValidation(function ($value) { @@ -78,7 +78,7 @@ public function validationOfMultiple() } /** @test */ - public function restrictsAddingAfterMultiple() + public function restrictsAddingAfterMultiple(): void { $operand1 = new Operand('op1', Operand::MULTIPLE); $operand2 = new Operand('op2', Operand::OPTIONAL); diff --git a/test/Operands/StrictTest.php b/test/Operands/StrictTest.php index e16491f..e4fd08d 100644 --- a/test/Operands/StrictTest.php +++ b/test/Operands/StrictTest.php @@ -10,7 +10,7 @@ class StrictTest extends TestCase { /** @test */ - public function noOperandsAllowed() + public function noOperandsAllowed(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_STRICT_OPERANDS, true); @@ -20,7 +20,7 @@ public function noOperandsAllowed() } /** @test */ - public function specifiedOperandsAllowed() + public function specifiedOperandsAllowed(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_STRICT_OPERANDS, true); @@ -32,7 +32,7 @@ public function specifiedOperandsAllowed() } /** @test */ - public function helpDoesNotShowAdditionalOperands() + public function helpDoesNotShowAdditionalOperands(): void { $getopt = new GetOpt(); $getopt->set(GetOpt::SETTING_STRICT_OPERANDS, true); diff --git a/test/Operands/ValueTest.php b/test/Operands/ValueTest.php index 0f0d0db..fe59097 100644 --- a/test/Operands/ValueTest.php +++ b/test/Operands/ValueTest.php @@ -8,7 +8,7 @@ class ValueTest extends TestCase { /** @test */ - public function toStringWithoutValue() + public function toStringWithoutValue(): void { $operand = Operand::create('file'); @@ -16,7 +16,7 @@ public function toStringWithoutValue() } /** @test */ - public function toStringWithDefaultValue() + public function toStringWithDefaultValue(): void { $operand = Operand::create('file') ->setDefaultValue('/dev/random'); @@ -25,7 +25,7 @@ public function toStringWithDefaultValue() } /** @test */ - public function toStringWithValue() + public function toStringWithValue(): void { $operand = Operand::create('file'); @@ -35,7 +35,7 @@ public function toStringWithValue() } /** @test */ - public function toStringWithMultipleValue() + public function toStringWithMultipleValue(): void { $operand = Operand::create('files', Operand::MULTIPLE); diff --git a/test/OptionParserTest.php b/test/OptionParserTest.php index 0882c9b..9328d30 100644 --- a/test/OptionParserTest.php +++ b/test/OptionParserTest.php @@ -12,16 +12,16 @@ class OptionParserTest extends TestCase /** @var OptionParser */ private $parser; - public function setUp() + public function setUp(): void { $this->parser = new OptionParser(GetOpt::REQUIRED_ARGUMENT); } /** @test */ - public function parseString() + public function parseString(): void { $options = $this->parser->parseString('ab:c::3'); - self::assertInternalType('array', $options); + self::assertIsArray($options); self::assertCount(4, $options); foreach ($options as $option) { self::assertInstanceOf(Option::CLASSNAME, $option); @@ -44,28 +44,28 @@ public function parseString() } /** @test */ - public function parseStringEmpty() + public function parseStringEmpty(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseString(''); } /** @test */ - public function parseStringInvalidCharacter() + public function parseStringInvalidCharacter(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseString('ab:c::dä'); } /** @test */ - public function parseStringStartsWithColon() + public function parseStringStartsWithColon(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseString(':ab:c::d'); } /** @test */ - public function parseStringTripleColon() + public function parseStringTripleColon(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseString('ab:c:::d'); @@ -83,7 +83,7 @@ public function provideOptionArrays() /** @dataProvider provideOptionArrays * @param array $array * @test */ - public function parseArray($array) + public function parseArray($array): void { $option = $this->parser->parseArray($array); @@ -112,14 +112,14 @@ public function parseArray($array) } /** @test */ - public function parseArrayEmpty() + public function parseArrayEmpty(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseArray([]); } /** @test */ - public function parseArrayInvalid() + public function parseArrayInvalid(): void { self::expectException(\InvalidArgumentException::class); $this->parser->parseArray([ 'a', '_' ]); diff --git a/test/Options/CommonTest.php b/test/Options/CommonTest.php index 1c5913c..43e2f26 100644 --- a/test/Options/CommonTest.php +++ b/test/Options/CommonTest.php @@ -10,7 +10,7 @@ class CommonTest extends TestCase { /** @test */ - public function construct() + public function construct(): void { $option = new Option('a', 'az-AZ09_', GetOpt::OPTIONAL_ARGUMENT); self::assertSame('a', $option->getShort()); @@ -19,7 +19,7 @@ public function construct() } /** @test */ - public function create() + public function create(): void { $option = Option::create('a', 'az-AZ09_', GetOpt::OPTIONAL_ARGUMENT); self::assertSame('a', $option->getShort()); @@ -32,7 +32,7 @@ public function create() * @param string $long * @param int $mode * @test */ - public function constructFails($short, $long, $mode) + public function constructFails($short, $long, $mode): void { self::expectException(\InvalidArgumentException::class); new Option($short, $long, $mode); @@ -50,7 +50,7 @@ public function dataConstructFails() } /** @test */ - public function setArgument() + public function setArgument(): void { $option = new Option('a', null, GetOpt::OPTIONAL_ARGUMENT); self::assertSame($option, $option->setArgument(new Argument())); @@ -58,7 +58,7 @@ public function setArgument() } /** @test */ - public function setArgumentWrongMode() + public function setArgumentWrongMode(): void { self::expectException(\InvalidArgumentException::class); $option = new Option('a', null, GetOpt::NO_ARGUMENT); @@ -66,7 +66,7 @@ public function setArgumentWrongMode() } /** @test */ - public function setDefaultValue() + public function setDefaultValue(): void { $option = new Option('a', null, GetOpt::OPTIONAL_ARGUMENT); self::assertSame($option, $option->setDefaultValue(10)); @@ -74,7 +74,7 @@ public function setDefaultValue() } /** @test */ - public function setValidation() + public function setValidation(): void { $option = new Option('a', null, GetOpt::OPTIONAL_ARGUMENT); self::assertSame($option, $option->setValidation('is_numeric')); diff --git a/test/Options/HelpTest.php b/test/Options/HelpTest.php index 1f2e0cd..c51843d 100644 --- a/test/Options/HelpTest.php +++ b/test/Options/HelpTest.php @@ -10,7 +10,7 @@ class HelpTest extends TestCase { /** @test */ - public function helpText() + public function helpText(): void { $getopt = new GetOpt([ [ 'a', 'alpha', GetOpt::NO_ARGUMENT, 'Short and long options with no argument' ], @@ -32,7 +32,7 @@ public function helpText() } /** @test */ - public function helpTextWithoutDescriptions() + public function helpTextWithoutDescriptions(): void { $getopt = new GetOpt([ [ 'a', 'alpha', GetOpt::NO_ARGUMENT ], @@ -53,7 +53,7 @@ public function helpTextWithoutDescriptions() } /** @test */ - public function helpTextWithLongDescriptions() + public function helpTextWithLongDescriptions(): void { defined('COLUMNS') || define('COLUMNS', 90); @@ -79,7 +79,7 @@ public function helpTextWithLongDescriptions() } /** @test */ - public function longWordsInDescription() + public function longWordsInDescription(): void { defined('COLUMNS') || define('COLUMNS', 90); @@ -105,7 +105,7 @@ public function longWordsInDescription() } /** @test */ - public function helpTextWithArgumentName() + public function helpTextWithArgumentName(): void { $getopt = new GetOpt([ Option::create('a', 'alpha', GetOpt::REQUIRED_ARGUMENT) @@ -122,7 +122,7 @@ public function helpTextWithArgumentName() } /** @test */ - public function textsGetUsed() + public function textsGetUsed(): void { $getopt = new GetOpt([Option::create('a', 'alpha')]); diff --git a/test/Options/NonStrictTest.php b/test/Options/NonStrictTest.php index 79130a9..79052ed 100644 --- a/test/Options/NonStrictTest.php +++ b/test/Options/NonStrictTest.php @@ -10,7 +10,7 @@ class NonStrictTest extends TestCase /** @var GetOpt */ protected $getopt; - protected function setUp() + protected function setUp(): void { $this->getopt = new GetOpt(null, [ GetOpt::SETTING_STRICT_OPTIONS => false, @@ -18,7 +18,7 @@ protected function setUp() } /** @test */ - public function additionalOptionsDoNotThrow() + public function additionalOptionsDoNotThrow(): void { $this->getopt->process('-a --beta'); @@ -26,7 +26,7 @@ public function additionalOptionsDoNotThrow() } /** @test */ - public function storesTheArgument() + public function storesTheArgument(): void { $this->getopt->process('-a aValue --beta betaValue -ccValue'); @@ -39,7 +39,7 @@ public function storesTheArgument() } /** @test */ - public function additionalOptionsAreResetted() + public function additionalOptionsAreResetted(): void { $this->getopt->process('-a aValue --beta betaValue -ccValue'); @@ -49,7 +49,7 @@ public function additionalOptionsAreResetted() } /** @test */ - public function iteratesOverAdditionalOptions() + public function iteratesOverAdditionalOptions(): void { $this->getopt->process('-a aValue --beta betaValue'); @@ -60,7 +60,7 @@ public function iteratesOverAdditionalOptions() } /** @test */ - public function offsetExists() + public function offsetExists(): void { $this->getopt->process('--alpha alphaValue'); @@ -68,7 +68,7 @@ public function offsetExists() } /** @test */ - public function offsetGet() + public function offsetGet(): void { $this->getopt->process('--alpha alphaValue'); @@ -76,7 +76,7 @@ public function offsetGet() } /** @test */ - public function storesTheCountWithoutValue() + public function storesTheCountWithoutValue(): void { $this->getopt->process('-a -a -a'); @@ -84,7 +84,7 @@ public function storesTheCountWithoutValue() } /** @test */ - public function showsOptionsInUsage() + public function showsOptionsInUsage(): void { $script = $_SERVER['PHP_SELF']; diff --git a/test/Options/ValueTest.php b/test/Options/ValueTest.php index de1c993..819a9aa 100644 --- a/test/Options/ValueTest.php +++ b/test/Options/ValueTest.php @@ -12,7 +12,7 @@ class ValueTest extends TestCase * @param Option $option * @param mixed $expected * @test */ - public function valueWithoutDefault(Option $option, $expected) + public function valueWithoutDefault(Option $option, $expected): void { $result = $option->getValue(); @@ -25,7 +25,7 @@ public function valueWithoutDefault(Option $option, $expected) * @param mixed $value * @param mixed $expected * @test */ - public function valueWithoutDefaultButSetValue(Option $option, $dummy, $value, $expected) + public function valueWithoutDefaultButSetValue(Option $option, $dummy, $value, $expected): void { $option->setValue($value); @@ -46,7 +46,7 @@ public function dataOptionsWithoutDefault() } /** @test */ - public function toStringWithoutArgument() + public function toStringWithoutArgument(): void { $option = new Option('a', null); $option->setValue(null); @@ -56,7 +56,7 @@ public function toStringWithoutArgument() } /** @test */ - public function toStringWithArgument() + public function toStringWithArgument(): void { $option = new Option('a', null, GetOpt::REQUIRED_ARGUMENT); $option->setValue('valueA'); @@ -65,7 +65,7 @@ public function toStringWithArgument() } /** @test */ - public function toStringWithMultipleArguments() + public function toStringWithMultipleArguments(): void { $option = new Option('a', null, GetOpt::MULTIPLE_ARGUMENT); $option->setValue('valueA'); @@ -75,7 +75,7 @@ public function toStringWithMultipleArguments() } /** @test */ - public function defaultValueNotUsedForCounting() + public function defaultValueNotUsedForCounting(): void { $option = new Option('a', null, GetOpt::OPTIONAL_ARGUMENT); $option->setDefaultValue(42); diff --git a/test/Printer.php b/test/Printer.php index 9ec1dad..a1a283e 100644 --- a/test/Printer.php +++ b/test/Printer.php @@ -5,9 +5,9 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\Test; use PHPUnit\Framework\Warning; -use PHPUnit\TextUI\ResultPrinter; +use PHPUnit\TextUI\DefaultResultPrinter; -class Printer extends ResultPrinter +class Printer extends DefaultResultPrinter { /** * Replacement symbols for test statuses. @@ -119,17 +119,17 @@ protected function writeProgressWithColor(string $color, string $buffer): void * @param $time * @param $color */ - protected function buildTestRow($className, $methodName, $time, $color = 'fg-white') + protected function buildTestRow($className, $methodName, $time, $color = 'fg-white'): void { if ($className != $this->previousClassName) { - $this->write(PHP_EOL . $this->formatWithColor('fg-magenta', $className) . PHP_EOL); + $this->write(PHP_EOL . $this->colorizeTextBox('fg-magenta', $className) . PHP_EOL); $this->previousClassName = $className; } $this->testRow = sprintf( "(%s) %s", $this->formatTestDuration($time), - $this->formatWithColor($color, "{$this->formatMethodName($methodName)}") + $this->colorizeTextBox($color, "{$this->formatMethodName($methodName)}") ); } /** @@ -176,7 +176,7 @@ protected function formatTestDuration($time) { $testDurationInMs = round($time * 1000); $duration = $testDurationInMs > 500 - ? $this->formatWithColor('fg-yellow', $testDurationInMs) + ? $this->colorizeTextBox('fg-yellow', $testDurationInMs) : $testDurationInMs; return sprintf('%s ms', $duration); } diff --git a/test/Translator/CommonTest.php b/test/Translator/CommonTest.php index 4f60d86..f438164 100644 --- a/test/Translator/CommonTest.php +++ b/test/Translator/CommonTest.php @@ -8,7 +8,7 @@ class CommonTest extends TestCase { /** @test */ - public function throwsWhenLanguageNotAvailable() + public function throwsWhenLanguageNotAvailable(): void { self::expectException(\InvalidArgumentException::class); @@ -16,7 +16,7 @@ public function throwsWhenLanguageNotAvailable() } /** @test */ - public function usesTranslationFile() + public function usesTranslationFile(): void { $translator = new Translator(__DIR__ . '/incomplete-translation.php'); @@ -26,7 +26,7 @@ public function usesTranslationFile() } /** @test */ - public function usesFallBackTranslation() + public function usesFallBackTranslation(): void { $translator = new Translator(__DIR__ . '/incomplete-translation.php'); From 8f34eed4ecb3d9fe0cf16f5e0c4024f023ff5ebb Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Fri, 11 Mar 2022 15:29:23 +0100 Subject: [PATCH 02/21] ignore platform requirements on 7.1 and 7.2 --- .gitlab-ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02ccb9d..7788acf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,10 +14,16 @@ php71-unit-test: extends: .php-unit-test image: iras/php7-composer:1 + before_script: + - mkdir -p .composer build/logs + - composer install --no-interaction --ignore-platform-reqs php72-unit-test: extends: .php-unit-test image: iras/php7-composer:2 + before_script: + - mkdir -p .composer build/logs + - composer install --no-interaction --ignore-platform-reqs php73-unit-test: extends: .php-unit-test @@ -40,6 +46,3 @@ php74-unit-test: php80-unit-test: extends: .php-unit-test image: iras/php8-composer:0 - before_script: - - mkdir -p .composer build/logs - - composer install --no-interaction --ignore-platform-reqs From e9eb44baa41a95a13efb7dd67aaf29cec2f88a5c Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Fri, 11 Mar 2022 15:55:50 +0100 Subject: [PATCH 03/21] replace custom printer with limedeck/phpunit-detailed-printer --- .gitlab-ci.yml | 6 -- composer.json | 5 +- phpunit.xml | 2 +- test/Printer.php | 203 ----------------------------------------------- 4 files changed, 4 insertions(+), 212 deletions(-) delete mode 100644 test/Printer.php diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7788acf..96cd111 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,16 +14,10 @@ php71-unit-test: extends: .php-unit-test image: iras/php7-composer:1 - before_script: - - mkdir -p .composer build/logs - - composer install --no-interaction --ignore-platform-reqs php72-unit-test: extends: .php-unit-test image: iras/php7-composer:2 - before_script: - - mkdir -p .composer build/logs - - composer install --no-interaction --ignore-platform-reqs php73-unit-test: extends: .php-unit-test diff --git a/composer.json b/composer.json index a08e2bc..fef0d76 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,9 @@ "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5.18", - "squizlabs/php_codesniffer": "^3.5.8" + "phpunit/phpunit": "*", + "squizlabs/php_codesniffer": "^3.5.8", + "limedeck/phpunit-detailed-printer": "*" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index f25c06e..032221b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ convertWarningsToExceptions="true" stopOnFailure="false" backupGlobals="true" - printerClass="\GetOpt\Test\Printer" + printerClass="LimeDeck\Testing\Printer" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> diff --git a/test/Printer.php b/test/Printer.php deleted file mode 100644 index a1a283e..0000000 --- a/test/Printer.php +++ /dev/null @@ -1,203 +0,0 @@ - "\e[31m!\e[0m", // red ! - 'F' => "\e[31m\xe2\x9c\x96\e[0m", // red X - 'W' => "\e[33mW\e[0m", // yellow W - 'I' => "\e[33mI\e[0m", // yellow I - 'R' => "\e[33mR\e[0m", // yellow R - 'S' => "\e[36mS\e[0m", // cyan S - '.' => "\e[32m\xe2\x9c\x94\e[0m", // green checkmark - ]; - /** - * Structure of the outputted test row. - * - * @var string - */ - protected $testRow = ''; - - /** @var string */ - protected $previousClassName = ''; - - /** - * {@inheritdoc} - */ - protected function writeProgress(string $progress): void - { - if ($this->hasReplacementSymbol($progress)) { - $progress = static::$symbols[$progress]; - } - $this->write(" {$progress} {$this->testRow}" . PHP_EOL); - $this->column++; - $this->numTestsRun++; - } - /** - * {@inheritdoc} - */ - public function addError(Test $test, \Throwable $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-red'); - parent::addError($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function addFailure(Test $test, AssertionFailedError $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-red'); - parent::addFailure($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function addWarning(Test $test, Warning $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-yellow'); - parent::addWarning($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function addIncompleteTest(Test $test, \Throwable $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-yellow'); - parent::addIncompleteTest($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function addRiskyTest(Test $test, \Throwable $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-yellow'); - parent::addRiskyTest($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function addSkippedTest(Test $test, \Throwable $e, float $time): void - { - $this->buildTestRow(get_class($test), $test->getName(), $time, 'fg-cyan'); - parent::addSkippedTest($test, $e, $time); - } - /** - * {@inheritdoc} - */ - public function endTest(Test $test, float $time): void - { - list($className, $methodName) = \PHPUnit\Util\Test::describe($test); - $this->buildTestRow($className, $methodName, $time); - parent::endTest($test, $time); - } - /** - * {@inheritdoc} - * - * We'll handle the coloring ourselves. - */ - protected function writeProgressWithColor(string $color, string $buffer): void - { - $this->writeProgress($buffer); - } - /** - * Formats the results for a single test. - * - * @param $className - * @param $methodName - * @param $time - * @param $color - */ - protected function buildTestRow($className, $methodName, $time, $color = 'fg-white'): void - { - if ($className != $this->previousClassName) { - $this->write(PHP_EOL . $this->colorizeTextBox('fg-magenta', $className) . PHP_EOL); - $this->previousClassName = $className; - } - - $this->testRow = sprintf( - "(%s) %s", - $this->formatTestDuration($time), - $this->colorizeTextBox($color, "{$this->formatMethodName($methodName)}") - ); - } - /** - * Makes the method name more readable. - * - * @param $method - * @return mixed - */ - protected function formatMethodName($method) - { - return ucfirst( - $this->splitCamels( - $this->splitSnakes($method) - ) - ); - } - /** - * Replaces underscores in snake case with spaces. - * - * @param $name - * @return string - */ - protected function splitSnakes($name) - { - return str_replace('_', ' ', $name); - } - /** - * Splits camel-cased names while handling caps sections properly. - * - * @param $name - * @return string - */ - protected function splitCamels($name) - { - return preg_replace('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', ' $1', $name); - } - /** - * Colours the duration if the test took longer than 500ms. - * - * @param $time - * @return string - */ - protected function formatTestDuration($time) - { - $testDurationInMs = round($time * 1000); - $duration = $testDurationInMs > 500 - ? $this->colorizeTextBox('fg-yellow', $testDurationInMs) - : $testDurationInMs; - return sprintf('%s ms', $duration); - } - /** - * Verifies if we have a replacement symbol available. - * - * @param $progress - * @return bool - */ - protected function hasReplacementSymbol($progress) - { - return in_array($progress, array_keys(static::$symbols)); - } - /** - * Checks if the class name is in format Class::method. - * - * @param $testName - * @return bool - */ - protected function hasCompoundClassName($testName) - { - return !empty($testName) && strpos($testName, '::') > -1; - } -} From 90405946b4cf7c2fd356f74bc561c96311a731a3 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Fri, 11 Mar 2022 16:20:53 +0100 Subject: [PATCH 04/21] install version 4 of the detailed printer in php 7.1 and 5 in 7.2 --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 96cd111..cf5c64c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,10 +14,16 @@ php71-unit-test: extends: .php-unit-test image: iras/php7-composer:1 + before_script: + - mkdir -p .composer build/logs + - composer require --no-interaction --dev limedeck/phpunit-detailed-printer "^4.0" php72-unit-test: extends: .php-unit-test image: iras/php7-composer:2 + before_script: + - mkdir -p .composer build/logs + - composer require --no-interaction --dev limedeck/phpunit-detailed-printer "^5.0" php73-unit-test: extends: .php-unit-test From a26dd88dec48e75478c85a09622878c6d8a819da Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Thu, 24 Mar 2022 15:50:30 +0100 Subject: [PATCH 05/21] use github actions for CI and switch to code climate --- .codeclimate.yml | 17 ++++++++ .github/workflows/push.yml | 81 ++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 48 ---------------------- composer.json | 6 +-- phpunit.xml | 2 +- 5 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 .codeclimate.yml create mode 100644 .github/workflows/push.yml delete mode 100644 .gitlab-ci.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..e633fef --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,17 @@ +version: "2" + +checks: + method-complexity: + config: + threshold: 9 + +exclude_patterns: + - "docs/" + - "**/test/" + - "**/vendor/" + +plugins: + phpcodesniffer: + enabled: true + config: + standard: "PSR2" diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..f7a98f9 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,81 @@ +on: [push, pull_request] +jobs: + before: + runs-on: ubuntu-latest + steps: + - name: Prepare CodeClimate + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + run: | + wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + + unit-tests: + needs: [before] + strategy: + matrix: + include: + - image: 'iras/php7-composer:1' + php_version: 7.1 + - image: 'iras/php7-composer:2' + php_version: 7.2 + - image: 'iras/php7-composer:3' + php_version: 7.3 + - image: 'iras/php7-composer:4' + php_version: 7.4 + - image: 'iras/php8-composer:0' + php_version: 8.0 + name: PHP Unit Tests on PHP ${{ matrix.php_version }} + runs-on: ubuntu-latest + container: ${{ matrix.image }} + steps: + - name: Container Setup + run: | + apk add --no-cache tar openssl + mkdir coverage + wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO /usr/bin/cc-test-reporter + chmod +x /usr/bin/cc-test-reporter + - name: Checkout + run: | + git init && git remote add origin https://github.com/${{ github.repository }}.git + git fetch origin ${{ github.sha }} && git reset --hard ${{ github.sha }} + - uses: actions/cache@v2 + with: + path: /composer/cache + key: composer-cache-7.${{ matrix.MINOR_VERSION }} + - name: Install dependencies + run: composer install --no-interaction --ansi + - name: Execute tests + run: | + php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit \ + -c phpunit.xml \ + --coverage-clover=coverage/clover.xml \ + --coverage-text \ + --color=always + - name: Format Coverage + run: | + cc-test-reporter format-coverage -t clover -o coverage/cc-${{ matrix.php_version }}.json coverage/clover.xml + - name: Store Coverage Result + uses: actions/upload-artifact@v3 + with: + name: coverage-results + path: coverage/ + + after: + needs: [unit-tests] + runs-on: ubuntu-latest + steps: + - name: Restore Coverage Result + uses: actions/download-artifact@v3 + with: + name: coverage-results + path: coverage/ + - name: Report Coverage + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + run: | + wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter sum-coverage coverage/cc-*.json -p 5 -o coverage/cc-total.json + ./cc-test-reporter upload-coverage -i coverage/cc-total.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index cf5c64c..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,48 +0,0 @@ -.php-unit-test: - stage: test - variables: - COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/.composer" - cache: - paths: - - .composer - before_script: - - mkdir -p .composer build/logs - - composer install --no-interaction - script: - - composer test -- --colors=always - -php71-unit-test: - extends: .php-unit-test - image: iras/php7-composer:1 - before_script: - - mkdir -p .composer build/logs - - composer require --no-interaction --dev limedeck/phpunit-detailed-printer "^4.0" - -php72-unit-test: - extends: .php-unit-test - image: iras/php7-composer:2 - before_script: - - mkdir -p .composer build/logs - - composer require --no-interaction --dev limedeck/phpunit-detailed-printer "^5.0" - -php73-unit-test: - extends: .php-unit-test - image: iras/php7-composer:3 - -php74-unit-test: - extends: .php-unit-test - image: iras/php7-composer:4 - variables: - CI_NAME: "gitalb-ci" - CI_BUILD_NUMBER: "$CI_JOB_ID" - CI_BRANCH: "$CI_COMMIT_REF_NAME" - CI_BUILD_URL: "$CI_JOB_URL" - script: - - php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit -c phpunit.xml --coverage-clover=build/coverage.xml --coverage-text --colors=always - after_script: - - composer require php-coveralls/php-coveralls:~2.4@stable - - php vendor/bin/php-coveralls -v -x build/coverage.xml - -php80-unit-test: - extends: .php-unit-test - image: iras/php8-composer:0 diff --git a/composer.json b/composer.json index fef0d76..993b892 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,13 @@ } ], "require": { - "php": ">=7.1 || ^8.0", + "php": "^7.1 || ^8.0", "ext-mbstring": "*" }, "require-dev": { "phpunit/phpunit": "*", - "squizlabs/php_codesniffer": "^3.5.8", - "limedeck/phpunit-detailed-printer": "*" + "tflori/phpunit-printer": "*", + "squizlabs/php_codesniffer": "^3.5.8" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 032221b..eb95eaa 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ convertWarningsToExceptions="true" stopOnFailure="false" backupGlobals="true" - printerClass="LimeDeck\Testing\Printer" + printerClass="PhpUnitPrinter\TextPrinter" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> From abbac72d22bdd1a620e11413e2208fedbc0dde7a Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Thu, 24 Mar 2022 15:56:52 +0100 Subject: [PATCH 06/21] restore phpunit 7 config Phpunit 9 is backward compatible but shows a warning. Of course phpunit 7 is not upward compatible (how could it?). --- phpunit.xml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index eb95eaa..327c8d1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,26 +1,21 @@ - - - - src - - - - - + test + + + + src + + From 351ff45775307cbc5389ab1fea6e892a5d64b2fa Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Thu, 24 Mar 2022 16:02:08 +0100 Subject: [PATCH 07/21] update status badges in readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67b9ef0..b298e91 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # GetOpt.PHP -[![Build Status](https://gitlab.com/thflori/getopt-php/badges/master/pipeline.svg)](https://gitlab.com/thflori/getopt-php/-/pipelines?ref=master) -[![Coverage Status](https://coveralls.io/repos/github/getopt-php/getopt-php/badge.svg?branch=master)](https://coveralls.io/github/getopt-php/getopt-php?branch=master) +[![.github/workflows/push.yml](https://github.com/getopt-php/getopt-php/actions/workflows/push.yml/badge.svg)](https://github.com/getopt-php/getopt-php/actions/workflows/push.yml) +[![Test Coverage](https://api.codeclimate.com/v1/badges/2f0b9586f3f69d690647/test_coverage)](https://codeclimate.com/github/getopt-php/getopt-php/test_coverage) +[![Maintainability](https://api.codeclimate.com/v1/badges/2f0b9586f3f69d690647/maintainability)](https://codeclimate.com/github/getopt-php/getopt-php/maintainability) [![Latest Stable Version](https://poser.pugx.org/ulrichsg/getopt-php/v/stable.svg)](https://packagist.org/packages/ulrichsg/getopt-php) [![Total Downloads](https://poser.pugx.org/ulrichsg/getopt-php/downloads.svg)](https://packagist.org/packages/ulrichsg/getopt-php) [![License](https://poser.pugx.org/ulrichsg/getopt-php/license.svg)](https://packagist.org/packages/ulrichsg/getopt-php) From 91c31c9bc0ff9bbe22b0b02c63c7f5ddb8d2a8d5 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Tue, 13 Dec 2022 21:37:45 +0100 Subject: [PATCH 08/21] add Catalan localization --- resources/localization/ca.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 resources/localization/ca.php diff --git a/resources/localization/ca.php b/resources/localization/ca.php new file mode 100644 index 0000000..fcb3d40 --- /dev/null +++ b/resources/localization/ca.php @@ -0,0 +1,16 @@ + 'Ús: ', + 'usage-command' => 'ordre', + 'usage-options' => 'opcions', + 'usage-operands' => 'operands', + 'operands-title' => "Operands:" . PHP_EOL, + 'options-title' => "Opcions:" . PHP_EOL, + 'commands-title' => "Ordres:" . PHP_EOL, + 'option-unknown' => 'L\'opció \'%s\' és desconeguda', + 'no-more-operands' => 'No s\'esperen més operands - obtingut %s', + 'operand-missing' => 'L\'operand %s és necessari', + 'option-argument-missing' => 'L\'opció \'%s\' ha de tenir un valor', + 'value-invalid' => '%s té un valor invàlid', +]; From 22c8cae31e7388e102419d2dde3ad0649fdb0500 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:09:24 +0000 Subject: [PATCH 09/21] Bump actions/download-artifact from 3 to 4.1.7 in /.github/workflows Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.1.7. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v3...v4.1.7) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f7a98f9..49ce983 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -67,7 +67,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Restore Coverage Result - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.7 with: name: coverage-results path: coverage/ From 0f49f47a9f07fe8717b3e9176472911c01e28981 Mon Sep 17 00:00:00 2001 From: AdamSGit Date: Sun, 9 Feb 2025 12:03:53 +0100 Subject: [PATCH 10/21] Fix php8.4 deprecated errors --- src/Argument.php | 6 +++--- src/Arguments.php | 8 ++++---- src/Option.php | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Argument.php b/src/Argument.php index b58ecf2..536fe21 100644 --- a/src/Argument.php +++ b/src/Argument.php @@ -45,7 +45,7 @@ class Argument implements Describable * @param ?callable $validation A validation function * @param string $name A name for the argument */ - public function __construct($default = null, callable $validation = null, $name = "arg") + public function __construct($default = null, ?callable $validation = null, $name = "arg") { if (!is_null($default)) { $this->setDefaultValue($default); @@ -77,10 +77,10 @@ public function setDefaultValue($value): Argument * The function must take a string and return true if it is valid, false otherwise. * * @param callable $callable - * @param string|callable $message + * @param string|callable|null $message * @return $this */ - public function setValidation(callable $callable, $message = null): Argument + public function setValidation(callable $callable, string|callable|null $message = null): Argument { $this->validation = $callable; $this->validationMessage = $message; diff --git a/src/Arguments.php b/src/Arguments.php index 2b35876..354c116 100644 --- a/src/Arguments.php +++ b/src/Arguments.php @@ -58,7 +58,7 @@ public function process(GetOpt $getopt, callable $setOption, callable $setComman } if ($this->isLongOption($arg)) { - $setOption($this->longName($arg), function (Option $option = null) use ($arg) { + $setOption($this->longName($arg), function (?Option $option = null) use ($arg) { return $this->value($arg, null, $option); }); continue; @@ -67,7 +67,7 @@ public function process(GetOpt $getopt, callable $setOption, callable $setComman // the only left is short options foreach ($this->shortNames($arg) as $name) { $requestedValue = false; - $setOption($name, function (Option $option = null) use ($arg, $name, &$requestedValue) { + $setOption($name, function (?Option $option = null) use ($arg, $name, &$requestedValue) { $requestedValue = true; return $this->value($arg, $name, $option); }); @@ -181,11 +181,11 @@ protected function shortNames(string $arg): array * Returns the value inside $arg or the next argument when it is a value. * * @param string $arg - * @param string $name + * @param ?string $name * @param ?Option $option * @return ?string */ - protected function value(string $arg, $name = null, Option $option = null): ?string + protected function value(string $arg, ?string $name = null, ?Option $option = null): ?string { $p = strpos($arg, $this->isLongOption($arg) ? '=' : $name); if ($this->isLongOption($arg) && $p || !$this->isLongOption($arg) && $p < strlen($arg)-1) { diff --git a/src/Option.php b/src/Option.php index 136889b..ccccb43 100644 --- a/src/Option.php +++ b/src/Option.php @@ -32,7 +32,7 @@ class Option implements Describable * or digit) or null for short-only options * @param string $mode Whether the option can/must have an argument (optional, defaults to no argument) */ - public function __construct(?string $short, string $long = null, string $mode = GetOpt::NO_ARGUMENT) + public function __construct(?string $short, ?string $long = null, string $mode = GetOpt::NO_ARGUMENT) { if (!$short && !$long) { throw new \InvalidArgumentException("The short and long name may not both be empty"); @@ -57,7 +57,7 @@ public function __construct(?string $short, string $long = null, string $mode = * @param string $mode * @return static */ - public static function create(?string $short, string $long = null, string $mode = GetOpt::NO_ARGUMENT): Option + public static function create(?string $short, ?string $long = null, string $mode = GetOpt::NO_ARGUMENT): Option { return new static($short, $long, $mode); } @@ -98,10 +98,10 @@ public function setDefaultValue($value): Option * Defines a validation function for the option. * * @param callable $function - * @param string|callable $message + * @param string|callable|null $message * @return Option this object (for chaining calls) */ - public function setValidation(callable $function, $message = null): Option + public function setValidation(callable $function, string|callable|null $message = null): Option { $this->argument->setValidation($function, $message); return $this; @@ -239,7 +239,7 @@ public function getArgument(): Argument * @param mixed $value * @return $this */ - public function setValue($value = null): Option + public function setValue(mixed $value = null): Option { if ($value === null) { if (in_array($this->mode, [ GetOpt::REQUIRED_ARGUMENT, GetOpt::MULTIPLE_ARGUMENT ])) { From 0f23d2b2a16cb82af79d3ddfa68603ba9f28c46c Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 14:32:50 +0100 Subject: [PATCH 11/21] update cache version of github actions --- .github/workflows/push.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 49ce983..f522310 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -16,15 +16,15 @@ jobs: strategy: matrix: include: - - image: 'iras/php7-composer:1' + - image: 'iras/php-composer:7.1' php_version: 7.1 - - image: 'iras/php7-composer:2' + - image: 'iras/php-composer:7.2' php_version: 7.2 - - image: 'iras/php7-composer:3' + - image: 'iras/php-composer:7.3' php_version: 7.3 - - image: 'iras/php7-composer:4' + - image: 'iras/php-composer:7.4' php_version: 7.4 - - image: 'iras/php8-composer:0' + - image: 'iras/php-composer:8.0' php_version: 8.0 name: PHP Unit Tests on PHP ${{ matrix.php_version }} runs-on: ubuntu-latest @@ -40,10 +40,10 @@ jobs: run: | git init && git remote add origin https://github.com/${{ github.repository }}.git git fetch origin ${{ github.sha }} && git reset --hard ${{ github.sha }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: /composer/cache - key: composer-cache-7.${{ matrix.MINOR_VERSION }} + key: composer-cache-${{ matrix.php_version }} - name: Install dependencies run: composer install --no-interaction --ansi - name: Execute tests From 43eab659ea075e716ce89abbffee90031644bae4 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 14:53:13 +0100 Subject: [PATCH 12/21] execute tests additionally on php 8.1, 8.2 and 8.3 --- .github/workflows/push.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f522310..fc4fb96 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -26,6 +26,12 @@ jobs: php_version: 7.4 - image: 'iras/php-composer:8.0' php_version: 8.0 + - image: 'iras/php-composer:8.1' + php_version: 8.1 + - image: 'iras/php-composer:8.2' + php_version: 8.2 + - image: 'iras/php-composer:8.3' + php_version: 8.3 name: PHP Unit Tests on PHP ${{ matrix.php_version }} runs-on: ubuntu-latest container: ${{ matrix.image }} @@ -77,5 +83,5 @@ jobs: run: | wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO ./cc-test-reporter chmod +x ./cc-test-reporter - ./cc-test-reporter sum-coverage coverage/cc-*.json -p 5 -o coverage/cc-total.json + ./cc-test-reporter sum-coverage coverage/cc-*.json -p 8 -o coverage/cc-total.json ./cc-test-reporter upload-coverage -i coverage/cc-total.json From 6980c6f073733b836931e112e2615a4a1c14f204 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 14:55:49 +0100 Subject: [PATCH 13/21] update action workflow --- .github/workflows/push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index fc4fb96..eb169c3 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -63,7 +63,7 @@ jobs: run: | cc-test-reporter format-coverage -t clover -o coverage/cc-${{ matrix.php_version }}.json coverage/clover.xml - name: Store Coverage Result - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: coverage-results path: coverage/ @@ -73,7 +73,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Restore Coverage Result - uses: actions/download-artifact@v4.1.7 + uses: actions/download-artifact@v4 with: name: coverage-results path: coverage/ From e05be76f0d04d689b2e776799de1627d08d65c6d Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 15:00:34 +0100 Subject: [PATCH 14/21] update action workflow --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index eb169c3..55ea9ca 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -46,7 +46,7 @@ jobs: run: | git init && git remote add origin https://github.com/${{ github.repository }}.git git fetch origin ${{ github.sha }} && git reset --hard ${{ github.sha }} - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: /composer/cache key: composer-cache-${{ matrix.php_version }} From eb2bfd74f1eaab6fce165a77f98074b3e37668d1 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 15:07:11 +0100 Subject: [PATCH 15/21] update action workflow --- .github/workflows/push.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 55ea9ca..ec52c23 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -16,21 +16,21 @@ jobs: strategy: matrix: include: - - image: 'iras/php-composer:7.1' + - image: 'iras/php-composer:ubuntu-7.1' php_version: 7.1 - - image: 'iras/php-composer:7.2' + - image: 'iras/php-composer:ubuntu-7.2' php_version: 7.2 - - image: 'iras/php-composer:7.3' + - image: 'iras/php-composer:ubuntu-7.3' php_version: 7.3 - - image: 'iras/php-composer:7.4' + - image: 'iras/php-composer:ubuntu-7.4' php_version: 7.4 - - image: 'iras/php-composer:8.0' + - image: 'iras/php-composer:ubuntu-8.0' php_version: 8.0 - - image: 'iras/php-composer:8.1' + - image: 'iras/php-composer:ubuntu-8.1' php_version: 8.1 - - image: 'iras/php-composer:8.2' + - image: 'iras/php-composer:ubuntu-8.2' php_version: 8.2 - - image: 'iras/php-composer:8.3' + - image: 'iras/php-composer:ubuntu-8.3' php_version: 8.3 name: PHP Unit Tests on PHP ${{ matrix.php_version }} runs-on: ubuntu-latest @@ -38,7 +38,7 @@ jobs: steps: - name: Container Setup run: | - apk add --no-cache tar openssl + apt-get update && apt-get install -y tar openssl wget mkdir coverage wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO /usr/bin/cc-test-reporter chmod +x /usr/bin/cc-test-reporter @@ -46,7 +46,7 @@ jobs: run: | git init && git remote add origin https://github.com/${{ github.repository }}.git git fetch origin ${{ github.sha }} && git reset --hard ${{ github.sha }} - - uses: actions/cache@v4 + - uses: actions/cache@v3 with: path: /composer/cache key: composer-cache-${{ matrix.php_version }} From 33a0113f9d2ef06ee3962c1449e00f5782da6e66 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 15:08:50 +0100 Subject: [PATCH 16/21] update action workflow --- .github/workflows/push.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ec52c23..e649f2d 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -43,9 +43,7 @@ jobs: wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO /usr/bin/cc-test-reporter chmod +x /usr/bin/cc-test-reporter - name: Checkout - run: | - git init && git remote add origin https://github.com/${{ github.repository }}.git - git fetch origin ${{ github.sha }} && git reset --hard ${{ github.sha }} + uses: actions/checkout@v3 - uses: actions/cache@v3 with: path: /composer/cache From 352e93fb78f1c0b8c510ecea3643cf50390dc9d1 Mon Sep 17 00:00:00 2001 From: AdamSGit Date: Mon, 10 Feb 2025 16:01:21 +0100 Subject: [PATCH 17/21] Untype multiple nullable arguments --- src/Argument.php | 4 ++-- src/Option.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Argument.php b/src/Argument.php index 536fe21..ec96368 100644 --- a/src/Argument.php +++ b/src/Argument.php @@ -77,10 +77,10 @@ public function setDefaultValue($value): Argument * The function must take a string and return true if it is valid, false otherwise. * * @param callable $callable - * @param string|callable|null $message + * @param string|callable|null $message (not typed for compatibility) * @return $this */ - public function setValidation(callable $callable, string|callable|null $message = null): Argument + public function setValidation(callable $callable, $message = null): Argument { $this->validation = $callable; $this->validationMessage = $message; diff --git a/src/Option.php b/src/Option.php index ccccb43..0d66373 100644 --- a/src/Option.php +++ b/src/Option.php @@ -98,10 +98,10 @@ public function setDefaultValue($value): Option * Defines a validation function for the option. * * @param callable $function - * @param string|callable|null $message + * @param string|callable|null $message (not typed for compatibility) * @return Option this object (for chaining calls) */ - public function setValidation(callable $function, string|callable|null $message = null): Option + public function setValidation(callable $function, $message = null): Option { $this->argument->setValidation($function, $message); return $this; From 856b736d9dee5fd1c99339d2bbbd39fdd3d506f0 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 17:16:49 +0100 Subject: [PATCH 18/21] update action workflow --- .github/workflows/push.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e649f2d..f644ef2 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -59,12 +59,13 @@ jobs: --color=always - name: Format Coverage run: | + git config --global --add safe.directory $GITHUB_WORKSPACE cc-test-reporter format-coverage -t clover -o coverage/cc-${{ matrix.php_version }}.json coverage/clover.xml - name: Store Coverage Result uses: actions/upload-artifact@v4 with: - name: coverage-results path: coverage/ + overwrite: true after: needs: [unit-tests] From bc30735c4fb28030e9acd2c26ff3dc087de57ed5 Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Mon, 10 Feb 2025 19:32:45 +0100 Subject: [PATCH 19/21] test: disable unit tests on php <8 --- .github/workflows/push.yml | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f644ef2..18f4374 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -16,22 +16,26 @@ jobs: strategy: matrix: include: - - image: 'iras/php-composer:ubuntu-7.1' - php_version: 7.1 - - image: 'iras/php-composer:ubuntu-7.2' - php_version: 7.2 - - image: 'iras/php-composer:ubuntu-7.3' - php_version: 7.3 - - image: 'iras/php-composer:ubuntu-7.4' - php_version: 7.4 +# - image: 'iras/php-composer:ubuntu-7.1' +# php_version: 7.1 +# - image: 'iras/php-composer:ubuntu-7.2' +# php_version: 7.2 +# - image: 'iras/php-composer:ubuntu-7.3' +# php_version: 7.3 +# - image: 'iras/php-composer:ubuntu-7.4' +# php_version: 7.4 - image: 'iras/php-composer:ubuntu-8.0' php_version: 8.0 + key: php80 - image: 'iras/php-composer:ubuntu-8.1' php_version: 8.1 + key: php81 - image: 'iras/php-composer:ubuntu-8.2' php_version: 8.2 + key: php82 - image: 'iras/php-composer:ubuntu-8.3' php_version: 8.3 + key: php83 name: PHP Unit Tests on PHP ${{ matrix.php_version }} runs-on: ubuntu-latest container: ${{ matrix.image }} @@ -47,7 +51,7 @@ jobs: - uses: actions/cache@v3 with: path: /composer/cache - key: composer-cache-${{ matrix.php_version }} + key: composer-cache-${{ matrix.key }} - name: Install dependencies run: composer install --no-interaction --ansi - name: Execute tests @@ -60,12 +64,12 @@ jobs: - name: Format Coverage run: | git config --global --add safe.directory $GITHUB_WORKSPACE - cc-test-reporter format-coverage -t clover -o coverage/cc-${{ matrix.php_version }}.json coverage/clover.xml + cc-test-reporter format-coverage -t clover -o coverage/cc-${{ matrix.key }}.json coverage/clover.xml - name: Store Coverage Result uses: actions/upload-artifact@v4 with: - path: coverage/ - overwrite: true + name: coverage-${{ matrix.key }} + path: coverage/cc-${{ matrix.key }}.json after: needs: [unit-tests] @@ -73,14 +77,13 @@ jobs: steps: - name: Restore Coverage Result uses: actions/download-artifact@v4 - with: - name: coverage-results - path: coverage/ - name: Report Coverage env: CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} run: | wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 -qO ./cc-test-reporter chmod +x ./cc-test-reporter - ./cc-test-reporter sum-coverage coverage/cc-*.json -p 8 -o coverage/cc-total.json + mkdir coverage && mv coverage-*/* coverage + ls -l coverage + ./cc-test-reporter sum-coverage coverage/cc-php*.json -p 4 -o coverage/cc-total.json ./cc-test-reporter upload-coverage -i coverage/cc-total.json From 9313ecde04f7bed262716e3a4d32a5e2cea3ffad Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Tue, 11 Feb 2025 13:52:11 +0100 Subject: [PATCH 20/21] fix code and re-enable tests for php <8 --- .github/workflows/push.yml | 22 +++++++++++++--------- src/Option.php | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 18f4374..2532faa 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -16,14 +16,18 @@ jobs: strategy: matrix: include: -# - image: 'iras/php-composer:ubuntu-7.1' -# php_version: 7.1 -# - image: 'iras/php-composer:ubuntu-7.2' -# php_version: 7.2 -# - image: 'iras/php-composer:ubuntu-7.3' -# php_version: 7.3 -# - image: 'iras/php-composer:ubuntu-7.4' -# php_version: 7.4 + - image: 'iras/php-composer:ubuntu-7.1' + php_version: 7.1 + key: php71 + - image: 'iras/php-composer:ubuntu-7.2' + php_version: 7.2 + key: php72 + - image: 'iras/php-composer:ubuntu-7.3' + php_version: 7.3 + key: php73 + - image: 'iras/php-composer:ubuntu-7.4' + php_version: 7.4 + key: php74 - image: 'iras/php-composer:ubuntu-8.0' php_version: 8.0 key: php80 @@ -85,5 +89,5 @@ jobs: chmod +x ./cc-test-reporter mkdir coverage && mv coverage-*/* coverage ls -l coverage - ./cc-test-reporter sum-coverage coverage/cc-php*.json -p 4 -o coverage/cc-total.json + ./cc-test-reporter sum-coverage coverage/cc-php*.json -p 8 -o coverage/cc-total.json ./cc-test-reporter upload-coverage -i coverage/cc-total.json diff --git a/src/Option.php b/src/Option.php index 0d66373..eaa2b1b 100644 --- a/src/Option.php +++ b/src/Option.php @@ -239,7 +239,7 @@ public function getArgument(): Argument * @param mixed $value * @return $this */ - public function setValue(mixed $value = null): Option + public function setValue($value = null): Option { if ($value === null) { if (in_array($this->mode, [ GetOpt::REQUIRED_ARGUMENT, GetOpt::MULTIPLE_ARGUMENT ])) { From ed9006ac30a3b55c5dd7c689f2c53cc6721e223e Mon Sep 17 00:00:00 2001 From: Thomas Flori Date: Thu, 2 Apr 2026 15:32:53 +0200 Subject: [PATCH 21/21] use empty string if description is null in OptionParser --- src/OptionParser.php | 6 ++--- test/OptionParserTest.php | 54 +++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/OptionParser.php b/src/OptionParser.php index faa9bb8..ccd9f1a 100644 --- a/src/OptionParser.php +++ b/src/OptionParser.php @@ -53,7 +53,7 @@ public static function parseString(string $string): array } /** - * Processes an option array. The array should be conform to the format + * Processes an option array. The array should conform to the format * (short, long, mode [, description [, default]]). See documentation for details. * * Developer note: Please don't add any further elements to the array. Future features should be configured only @@ -70,13 +70,13 @@ public static function parseArray(array $array): Option $rowSize = count($array); if ($rowSize < 3) { - $array = self::completeOptionArray($array); + return new Option(...self::completeOptionArray($array)); } $option = new Option($array[0], $array[1], $array[2]); if ($rowSize >= 4) { - $option->setDescription($array[3]); + $option->setDescription($array[3] ?? ''); } if ($rowSize >= 5 && $array[2] != GetOpt::NO_ARGUMENT) { diff --git a/test/OptionParserTest.php b/test/OptionParserTest.php index 9328d30..9e31a70 100644 --- a/test/OptionParserTest.php +++ b/test/OptionParserTest.php @@ -14,7 +14,9 @@ class OptionParserTest extends TestCase public function setUp(): void { - $this->parser = new OptionParser(GetOpt::REQUIRED_ARGUMENT); + $this->parser = new OptionParser(); + // reset default mode + $this->parser::$defaultMode = GetOpt::NO_ARGUMENT; } /** @test */ @@ -74,41 +76,39 @@ public function parseStringTripleColon(): void public function provideOptionArrays() { return [ - [ [ 'a', 'alpha', GetOpt::OPTIONAL_ARGUMENT, 'Description', 42 ] ], - [ [ 'b', 'beta' ] ], - [ [ 'c' ] ], + [ + [ 'a', 'alpha', GetOpt::OPTIONAL_ARGUMENT, 'Description', 42 ], + Option::create('a', 'alpha', GetOpt::OPTIONAL_ARGUMENT) + ->setDescription('Description') + ->setDefaultValue(42), + ], + [ + [ 'b', 'beta'], + Option::create('b', 'beta'), + ], + [ + [ 'c' ], + Option::create('c'), + ], + [ + [ 'delta', GetOpt::REQUIRED_ARGUMENT ], + Option::create(null, 'delta', GetOpt::REQUIRED_ARGUMENT), + ], + [ + [ 'e', 'epsilon', GetOpt::OPTIONAL_ARGUMENT, null], + Option::create('e', 'epsilon', GetOpt::OPTIONAL_ARGUMENT), + ] ]; } /** @dataProvider provideOptionArrays * @param array $array * @test */ - public function parseArray($array): void + public function parseArray($array, $expected): void { $option = $this->parser->parseArray($array); - self::assertInstanceOf(Option::CLASSNAME, $option); - switch ($option->getShort()) { - case 'a': - self::assertSame('alpha', $option->getLong()); - self::assertSame(GetOpt::OPTIONAL_ARGUMENT, $option->getMode()); - self::assertSame('Description', $option->getDescription()); - self::assertSame(42, $option->getArgument()->getDefaultValue()); - break; - case 'b': - self::assertSame('beta', $option->getLong()); - self::assertSame(GetOpt::REQUIRED_ARGUMENT, $option->getMode()); - self::assertSame('', $option->getDescription()); - break; - case 'c': - self::assertNull($option->getLong()); - self::assertSame(GetOpt::REQUIRED_ARGUMENT, $option->getMode()); - self::assertSame('', $option->getDescription()); - self::assertFalse($option->getArgument()->hasDefaultValue()); - break; - default: - $this->fail('Unexpected option: '.$option->getShort()); - } + self::assertEquals($expected, $option); } /** @test */