@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use Symfony\Component\Console\Input\ArgvInput; |
| 7 | 7 | |
| 8 | 8 | if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { |
| 9 | - echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; |
|
| 9 | + echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | set_time_limit(0); |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | $input = new ArgvInput(); |
| 20 | 20 | if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { |
| 21 | - putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); |
|
| 21 | + putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if ($input->hasParameterOption('--no-debug', true)) { |
| 25 | - putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); |
|
| 25 | + putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | if ($_SERVER['APP_DEBUG']) { |
| 29 | - umask(0000); |
|
| 29 | + umask(0000); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | umask(0000); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); |
|
| 32 | +$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']); |
|
| 33 | 33 | |
| 34 | 34 | $application = new Application($kernel); |
| 35 | 35 | $application->run($input); |
@@ -31,188 +31,188 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | final class IOTest extends TestCase |
| 33 | 33 | { |
| 34 | - public function test_it_exposes_its_input_and_output(): void |
|
| 35 | - { |
|
| 36 | - $input = new StringInput(''); |
|
| 37 | - $output = new NullOutput(); |
|
| 38 | - |
|
| 39 | - $io = new IO($input, $output); |
|
| 40 | - |
|
| 41 | - self::assertSame($input, $io->getInput()); |
|
| 42 | - self::assertSame($output, $io->getOutput()); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @dataProvider inputProvider |
|
| 47 | - */ |
|
| 48 | - public function test_it_exposes_if_its_input_is_interactive( |
|
| 49 | - InputInterface $input, |
|
| 50 | - bool $expectedInteractivity |
|
| 51 | - ): void { |
|
| 52 | - $output = new NullOutput(); |
|
| 53 | - |
|
| 54 | - $io = new IO($input, $output); |
|
| 55 | - |
|
| 56 | - self::assertSame($expectedInteractivity, $io->isInteractive()); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public static function inputProvider(): iterable |
|
| 60 | - { |
|
| 61 | - foreach ([true, false] as $interactive) { |
|
| 62 | - yield [ |
|
| 63 | - self::createInput($interactive), |
|
| 64 | - $interactive, |
|
| 65 | - ]; |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function test_it_can_create_a_null_io(): void |
|
| 70 | - { |
|
| 71 | - $io = IO::createNull(); |
|
| 72 | - |
|
| 73 | - self::assertCount(0, $io->getInput()->getArguments()); |
|
| 74 | - self::assertCount(0, $io->getInput()->getOptions()); |
|
| 75 | - |
|
| 76 | - self::assertInstanceOf(NullOutput::class, $io->getOutput()); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @dataProvider invalidScalarArgumentTypeProvider |
|
| 81 | - * @dataProvider invalidArrayArgumentTypeProvider |
|
| 82 | - * |
|
| 83 | - * @param mixed $default |
|
| 84 | - */ |
|
| 85 | - public function test_it_checks_against_invalid_argument_default_types( |
|
| 86 | - $default, |
|
| 87 | - string $expectedMessage |
|
| 88 | - ): void { |
|
| 89 | - $io = new IO( |
|
| 90 | - new ArrayInput( |
|
| 91 | - [], |
|
| 92 | - new InputDefinition( |
|
| 93 | - [ |
|
| 94 | - new InputArgument( |
|
| 95 | - 'arg', |
|
| 96 | - InputArgument::OPTIONAL, |
|
| 97 | - '', |
|
| 98 | - $default, |
|
| 99 | - ), |
|
| 100 | - ], |
|
| 101 | - ), |
|
| 102 | - ), |
|
| 103 | - new NullOutput(), |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - $this->expectException(ConsoleInvalidArgumentException::class); |
|
| 107 | - $this->expectExceptionMessage($expectedMessage); |
|
| 108 | - |
|
| 109 | - $io->getStringArgument('arg'); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public static function invalidScalarArgumentTypeProvider(): iterable |
|
| 113 | - { |
|
| 114 | - yield 'boolean' => [ |
|
| 115 | - false, |
|
| 116 | - 'Expected an argument value type to be "null|string|string[]". Got "bool"', |
|
| 117 | - ]; |
|
| 118 | - |
|
| 119 | - yield 'int' => [ |
|
| 120 | - 10, |
|
| 121 | - 'Expected an argument value type to be "null|string|string[]". Got "int"', |
|
| 122 | - ]; |
|
| 123 | - |
|
| 124 | - yield 'float' => [ |
|
| 125 | - 10.8, |
|
| 126 | - 'Expected an argument value type to be "null|string|string[]". Got "float"', |
|
| 127 | - ]; |
|
| 128 | - |
|
| 129 | - yield 'object' => [ |
|
| 130 | - new stdClass(), |
|
| 131 | - 'Expected an argument value type to be "null|string|string[]". Got "stdClass"', |
|
| 132 | - ]; |
|
| 133 | - |
|
| 134 | - yield 'closure' => [ |
|
| 135 | - static fn () => '', |
|
| 136 | - 'Expected an argument value type to be "null|string|string[]". Got "Closure"', |
|
| 137 | - ]; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public static function invalidArrayArgumentTypeProvider(): iterable |
|
| 141 | - { |
|
| 142 | - foreach (self::invalidScalarArgumentTypeProvider() as [$item, $message]) { |
|
| 143 | - yield [[$item], $message]; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @dataProvider invalidScalarOptionTypeProvider |
|
| 149 | - * @dataProvider invalidArrayOptionTypeProvider |
|
| 150 | - * |
|
| 151 | - * @param mixed $default |
|
| 152 | - */ |
|
| 153 | - public function test_it_checks_against_invalid_option_default_types( |
|
| 154 | - $default, |
|
| 155 | - string $expectedMessage |
|
| 156 | - ): void { |
|
| 157 | - $io = new IO( |
|
| 158 | - new ArrayInput( |
|
| 159 | - [], |
|
| 160 | - new InputDefinition( |
|
| 161 | - [ |
|
| 162 | - new InputOption( |
|
| 163 | - 'opt', |
|
| 164 | - null, |
|
| 165 | - InputOption::VALUE_OPTIONAL, |
|
| 166 | - '', |
|
| 167 | - $default, |
|
| 168 | - ), |
|
| 169 | - ], |
|
| 170 | - ), |
|
| 171 | - ), |
|
| 172 | - new NullOutput(), |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - $this->expectException(ConsoleInvalidArgumentException::class); |
|
| 176 | - $this->expectExceptionMessage($expectedMessage); |
|
| 177 | - |
|
| 178 | - $io->getStringOption('opt'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - public static function invalidScalarOptionTypeProvider(): iterable |
|
| 182 | - { |
|
| 183 | - yield 'int' => [ |
|
| 184 | - 10, |
|
| 185 | - 'Expected an option value type to be "null|bool|string|string[]". Got "int"', |
|
| 186 | - ]; |
|
| 187 | - |
|
| 188 | - yield 'float' => [ |
|
| 189 | - 10.8, |
|
| 190 | - 'Expected an option value type to be "null|bool|string|string[]". Got "float"', |
|
| 191 | - ]; |
|
| 192 | - |
|
| 193 | - yield 'object' => [ |
|
| 194 | - new stdClass(), |
|
| 195 | - 'Expected an option value type to be "null|bool|string|string[]". Got "stdClass"', |
|
| 196 | - ]; |
|
| 197 | - |
|
| 198 | - yield 'closure' => [ |
|
| 199 | - static fn () => '', |
|
| 200 | - 'Expected an option value type to be "null|bool|string|string[]". Got "Closure"', |
|
| 201 | - ]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - public static function invalidArrayOptionTypeProvider(): iterable |
|
| 205 | - { |
|
| 206 | - foreach (self::invalidScalarOptionTypeProvider() as [$item, $message]) { |
|
| 207 | - yield [[$item], $message]; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - private static function createInput(bool $interactive): InputInterface |
|
| 212 | - { |
|
| 213 | - $input = new StringInput(''); |
|
| 214 | - $input->setInteractive($interactive); |
|
| 215 | - |
|
| 216 | - return $input; |
|
| 217 | - } |
|
| 34 | + public function test_it_exposes_its_input_and_output(): void |
|
| 35 | + { |
|
| 36 | + $input = new StringInput(''); |
|
| 37 | + $output = new NullOutput(); |
|
| 38 | + |
|
| 39 | + $io = new IO($input, $output); |
|
| 40 | + |
|
| 41 | + self::assertSame($input, $io->getInput()); |
|
| 42 | + self::assertSame($output, $io->getOutput()); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @dataProvider inputProvider |
|
| 47 | + */ |
|
| 48 | + public function test_it_exposes_if_its_input_is_interactive( |
|
| 49 | + InputInterface $input, |
|
| 50 | + bool $expectedInteractivity |
|
| 51 | + ): void { |
|
| 52 | + $output = new NullOutput(); |
|
| 53 | + |
|
| 54 | + $io = new IO($input, $output); |
|
| 55 | + |
|
| 56 | + self::assertSame($expectedInteractivity, $io->isInteractive()); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public static function inputProvider(): iterable |
|
| 60 | + { |
|
| 61 | + foreach ([true, false] as $interactive) { |
|
| 62 | + yield [ |
|
| 63 | + self::createInput($interactive), |
|
| 64 | + $interactive, |
|
| 65 | + ]; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function test_it_can_create_a_null_io(): void |
|
| 70 | + { |
|
| 71 | + $io = IO::createNull(); |
|
| 72 | + |
|
| 73 | + self::assertCount(0, $io->getInput()->getArguments()); |
|
| 74 | + self::assertCount(0, $io->getInput()->getOptions()); |
|
| 75 | + |
|
| 76 | + self::assertInstanceOf(NullOutput::class, $io->getOutput()); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @dataProvider invalidScalarArgumentTypeProvider |
|
| 81 | + * @dataProvider invalidArrayArgumentTypeProvider |
|
| 82 | + * |
|
| 83 | + * @param mixed $default |
|
| 84 | + */ |
|
| 85 | + public function test_it_checks_against_invalid_argument_default_types( |
|
| 86 | + $default, |
|
| 87 | + string $expectedMessage |
|
| 88 | + ): void { |
|
| 89 | + $io = new IO( |
|
| 90 | + new ArrayInput( |
|
| 91 | + [], |
|
| 92 | + new InputDefinition( |
|
| 93 | + [ |
|
| 94 | + new InputArgument( |
|
| 95 | + 'arg', |
|
| 96 | + InputArgument::OPTIONAL, |
|
| 97 | + '', |
|
| 98 | + $default, |
|
| 99 | + ), |
|
| 100 | + ], |
|
| 101 | + ), |
|
| 102 | + ), |
|
| 103 | + new NullOutput(), |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + $this->expectException(ConsoleInvalidArgumentException::class); |
|
| 107 | + $this->expectExceptionMessage($expectedMessage); |
|
| 108 | + |
|
| 109 | + $io->getStringArgument('arg'); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public static function invalidScalarArgumentTypeProvider(): iterable |
|
| 113 | + { |
|
| 114 | + yield 'boolean' => [ |
|
| 115 | + false, |
|
| 116 | + 'Expected an argument value type to be "null|string|string[]". Got "bool"', |
|
| 117 | + ]; |
|
| 118 | + |
|
| 119 | + yield 'int' => [ |
|
| 120 | + 10, |
|
| 121 | + 'Expected an argument value type to be "null|string|string[]". Got "int"', |
|
| 122 | + ]; |
|
| 123 | + |
|
| 124 | + yield 'float' => [ |
|
| 125 | + 10.8, |
|
| 126 | + 'Expected an argument value type to be "null|string|string[]". Got "float"', |
|
| 127 | + ]; |
|
| 128 | + |
|
| 129 | + yield 'object' => [ |
|
| 130 | + new stdClass(), |
|
| 131 | + 'Expected an argument value type to be "null|string|string[]". Got "stdClass"', |
|
| 132 | + ]; |
|
| 133 | + |
|
| 134 | + yield 'closure' => [ |
|
| 135 | + static fn () => '', |
|
| 136 | + 'Expected an argument value type to be "null|string|string[]". Got "Closure"', |
|
| 137 | + ]; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public static function invalidArrayArgumentTypeProvider(): iterable |
|
| 141 | + { |
|
| 142 | + foreach (self::invalidScalarArgumentTypeProvider() as [$item, $message]) { |
|
| 143 | + yield [[$item], $message]; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @dataProvider invalidScalarOptionTypeProvider |
|
| 149 | + * @dataProvider invalidArrayOptionTypeProvider |
|
| 150 | + * |
|
| 151 | + * @param mixed $default |
|
| 152 | + */ |
|
| 153 | + public function test_it_checks_against_invalid_option_default_types( |
|
| 154 | + $default, |
|
| 155 | + string $expectedMessage |
|
| 156 | + ): void { |
|
| 157 | + $io = new IO( |
|
| 158 | + new ArrayInput( |
|
| 159 | + [], |
|
| 160 | + new InputDefinition( |
|
| 161 | + [ |
|
| 162 | + new InputOption( |
|
| 163 | + 'opt', |
|
| 164 | + null, |
|
| 165 | + InputOption::VALUE_OPTIONAL, |
|
| 166 | + '', |
|
| 167 | + $default, |
|
| 168 | + ), |
|
| 169 | + ], |
|
| 170 | + ), |
|
| 171 | + ), |
|
| 172 | + new NullOutput(), |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + $this->expectException(ConsoleInvalidArgumentException::class); |
|
| 176 | + $this->expectExceptionMessage($expectedMessage); |
|
| 177 | + |
|
| 178 | + $io->getStringOption('opt'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + public static function invalidScalarOptionTypeProvider(): iterable |
|
| 182 | + { |
|
| 183 | + yield 'int' => [ |
|
| 184 | + 10, |
|
| 185 | + 'Expected an option value type to be "null|bool|string|string[]". Got "int"', |
|
| 186 | + ]; |
|
| 187 | + |
|
| 188 | + yield 'float' => [ |
|
| 189 | + 10.8, |
|
| 190 | + 'Expected an option value type to be "null|bool|string|string[]". Got "float"', |
|
| 191 | + ]; |
|
| 192 | + |
|
| 193 | + yield 'object' => [ |
|
| 194 | + new stdClass(), |
|
| 195 | + 'Expected an option value type to be "null|bool|string|string[]". Got "stdClass"', |
|
| 196 | + ]; |
|
| 197 | + |
|
| 198 | + yield 'closure' => [ |
|
| 199 | + static fn () => '', |
|
| 200 | + 'Expected an option value type to be "null|bool|string|string[]". Got "Closure"', |
|
| 201 | + ]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + public static function invalidArrayOptionTypeProvider(): iterable |
|
| 205 | + { |
|
| 206 | + foreach (self::invalidScalarOptionTypeProvider() as [$item, $message]) { |
|
| 207 | + yield [[$item], $message]; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + private static function createInput(bool $interactive): InputInterface |
|
| 212 | + { |
|
| 213 | + $input = new StringInput(''); |
|
| 214 | + $input->setInteractive($interactive); |
|
| 215 | + |
|
| 216 | + return $input; |
|
| 217 | + } |
|
| 218 | 218 | } |
@@ -29,8 +29,7 @@ |
||
| 29 | 29 | * @covers \Fidry\Console\Command\ConsoleAssert |
| 30 | 30 | * @covers \Fidry\Console\IO |
| 31 | 31 | */ |
| 32 | -final class IOTest extends TestCase |
|
| 33 | -{ |
|
| 32 | +final class IOTest extends TestCase { |
|
| 34 | 33 | public function test_it_exposes_its_input_and_output(): void |
| 35 | 34 | { |
| 36 | 35 | $input = new StringInput(''); |
@@ -21,22 +21,22 @@ |
||
| 21 | 21 | |
| 22 | 22 | final class DynamicCommandWithArguments extends Command |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @psalm-suppress PropertyNotSetInConstructor |
|
| 26 | - */ |
|
| 27 | - public InputInterface $input; |
|
| 24 | + /** |
|
| 25 | + * @psalm-suppress PropertyNotSetInConstructor |
|
| 26 | + */ |
|
| 27 | + public InputInterface $input; |
|
| 28 | 28 | |
| 29 | - public function __construct(InputArgument $inputArgument) |
|
| 30 | - { |
|
| 31 | - parent::__construct('app:input:args'); |
|
| 29 | + public function __construct(InputArgument $inputArgument) |
|
| 30 | + { |
|
| 31 | + parent::__construct('app:input:args'); |
|
| 32 | 32 | |
| 33 | - $this->getDefinition()->addArgument($inputArgument); |
|
| 34 | - } |
|
| 33 | + $this->getDefinition()->addArgument($inputArgument); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 37 | - { |
|
| 38 | - $this->input = $input; |
|
| 36 | + protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 37 | + { |
|
| 38 | + $this->input = $input; |
|
| 39 | 39 | |
| 40 | - return ExitCode::SUCCESS; |
|
| 41 | - } |
|
| 40 | + return ExitCode::SUCCESS; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | use Symfony\Component\Console\Input\InputInterface; |
| 20 | 20 | use Symfony\Component\Console\Output\OutputInterface; |
| 21 | 21 | |
| 22 | -final class DynamicCommandWithArguments extends Command |
|
| 23 | -{ |
|
| 22 | +final class DynamicCommandWithArguments extends Command { |
|
| 24 | 23 | /** |
| 25 | 24 | * @psalm-suppress PropertyNotSetInConstructor |
| 26 | 25 | */ |
@@ -26,483 +26,483 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | final class IOOptionsTest extends TestCase |
| 28 | 28 | { |
| 29 | - private const OPTION_NAME = 'opt'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @dataProvider requiredOptionProvider |
|
| 33 | - * @dataProvider optionalOptionProvider |
|
| 34 | - * @dataProvider noValueOptionProvider |
|
| 35 | - * @dataProvider arrayOptionProvider |
|
| 36 | - */ |
|
| 37 | - public function test_it_exposes_a_typed_api( |
|
| 38 | - InputOption $inputOption, |
|
| 39 | - string $option, |
|
| 40 | - TypedInput $expected |
|
| 41 | - ): void { |
|
| 42 | - $io = $this->getIO($inputOption, $option); |
|
| 43 | - |
|
| 44 | - TypeAssertions::assertExpectedOptionTypes( |
|
| 45 | - $expected, |
|
| 46 | - $io, |
|
| 47 | - self::OPTION_NAME, |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public static function requiredOptionProvider(): iterable |
|
| 52 | - { |
|
| 53 | - $mode = InputOption::VALUE_REQUIRED; |
|
| 54 | - |
|
| 55 | - yield 'empty string' => [ |
|
| 56 | - new InputOption( |
|
| 57 | - self::OPTION_NAME, |
|
| 58 | - null, |
|
| 59 | - $mode, |
|
| 60 | - '', |
|
| 61 | - null, |
|
| 62 | - ), |
|
| 63 | - '--opt=""', |
|
| 64 | - TypedInput::createForScalar( |
|
| 65 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'\'"'), |
|
| 66 | - false, |
|
| 67 | - false, |
|
| 68 | - '', |
|
| 69 | - '', |
|
| 70 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 71 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 72 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 73 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 74 | - ), |
|
| 75 | - ]; |
|
| 76 | - |
|
| 77 | - yield 'nominal string' => [ |
|
| 78 | - new InputOption( |
|
| 79 | - self::OPTION_NAME, |
|
| 80 | - null, |
|
| 81 | - $mode, |
|
| 82 | - '', |
|
| 83 | - null, |
|
| 84 | - ), |
|
| 85 | - '--opt=foo', |
|
| 86 | - TypedInput::createForScalar( |
|
| 87 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'foo\'"'), |
|
| 88 | - true, |
|
| 89 | - true, |
|
| 90 | - 'foo', |
|
| 91 | - 'foo', |
|
| 92 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 93 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 94 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 95 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 96 | - ), |
|
| 97 | - ]; |
|
| 98 | - |
|
| 99 | - yield 'null string' => [ |
|
| 100 | - new InputOption( |
|
| 101 | - self::OPTION_NAME, |
|
| 102 | - null, |
|
| 103 | - $mode, |
|
| 104 | - '', |
|
| 105 | - null, |
|
| 106 | - ), |
|
| 107 | - '--opt=null', |
|
| 108 | - TypedInput::createForScalar( |
|
| 109 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'null\'"'), |
|
| 110 | - true, |
|
| 111 | - true, |
|
| 112 | - 'null', |
|
| 113 | - 'null', |
|
| 114 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 115 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 116 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 117 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 118 | - ), |
|
| 119 | - ]; |
|
| 120 | - |
|
| 121 | - yield 'integer string' => [ |
|
| 122 | - new InputOption( |
|
| 123 | - self::OPTION_NAME, |
|
| 124 | - null, |
|
| 125 | - $mode, |
|
| 126 | - '', |
|
| 127 | - null, |
|
| 128 | - ), |
|
| 129 | - '--opt=10', |
|
| 130 | - TypedInput::createForScalar( |
|
| 131 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10\'"'), |
|
| 132 | - true, |
|
| 133 | - true, |
|
| 134 | - '10', |
|
| 135 | - '10', |
|
| 136 | - 10, |
|
| 137 | - 10, |
|
| 138 | - 10., |
|
| 139 | - 10., |
|
| 140 | - ), |
|
| 141 | - ]; |
|
| 142 | - |
|
| 143 | - // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 144 | - |
|
| 145 | - yield 'zero integer string' => [ |
|
| 146 | - new InputOption( |
|
| 147 | - self::OPTION_NAME, |
|
| 148 | - null, |
|
| 149 | - $mode, |
|
| 150 | - '', |
|
| 151 | - null, |
|
| 152 | - ), |
|
| 153 | - '--opt=0', |
|
| 154 | - TypedInput::createForScalar( |
|
| 155 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0\'"'), |
|
| 156 | - false, |
|
| 157 | - false, |
|
| 158 | - '0', |
|
| 159 | - '0', |
|
| 160 | - 0, |
|
| 161 | - 0, |
|
| 162 | - 0., |
|
| 163 | - 0., |
|
| 164 | - ), |
|
| 165 | - ]; |
|
| 166 | - |
|
| 167 | - yield 'float string' => [ |
|
| 168 | - new InputOption( |
|
| 169 | - self::OPTION_NAME, |
|
| 170 | - null, |
|
| 171 | - $mode, |
|
| 172 | - '', |
|
| 173 | - null, |
|
| 174 | - ), |
|
| 175 | - '--opt=10.8', |
|
| 176 | - TypedInput::createForScalar( |
|
| 177 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10.8\'"'), |
|
| 178 | - true, |
|
| 179 | - true, |
|
| 180 | - '10.8', |
|
| 181 | - '10.8', |
|
| 182 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 183 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 184 | - 10.8, |
|
| 185 | - 10.8, |
|
| 186 | - ), |
|
| 187 | - ]; |
|
| 188 | - |
|
| 189 | - // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 190 | - |
|
| 191 | - yield 'zero float string' => [ |
|
| 192 | - new InputOption( |
|
| 193 | - self::OPTION_NAME, |
|
| 194 | - null, |
|
| 195 | - $mode, |
|
| 196 | - '', |
|
| 197 | - null, |
|
| 198 | - ), |
|
| 199 | - '--opt=0.', |
|
| 200 | - TypedInput::createForScalar( |
|
| 201 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0.\'"'), |
|
| 202 | - true, |
|
| 203 | - true, |
|
| 204 | - '0.', |
|
| 205 | - '0.', |
|
| 206 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 207 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 208 | - 0., |
|
| 209 | - 0., |
|
| 210 | - ), |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - public static function optionalOptionProvider(): iterable |
|
| 215 | - { |
|
| 216 | - yield 'empty string' => [ |
|
| 217 | - new InputOption( |
|
| 218 | - self::OPTION_NAME, |
|
| 219 | - null, |
|
| 220 | - InputOption::VALUE_OPTIONAL, |
|
| 221 | - '', |
|
| 222 | - null, |
|
| 223 | - ), |
|
| 224 | - '', |
|
| 225 | - TypedInput::createForScalar( |
|
| 226 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "NULL"'), |
|
| 227 | - false, |
|
| 228 | - null, |
|
| 229 | - '', |
|
| 230 | - null, |
|
| 231 | - new TypeException('Expected an integer. Got "NULL"'), |
|
| 232 | - null, |
|
| 233 | - new TypeException('Expected a numeric. Got "NULL"'), |
|
| 234 | - null, |
|
| 235 | - ), |
|
| 236 | - ]; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public static function noValueOptionProvider(): iterable |
|
| 240 | - { |
|
| 241 | - $mode = InputOption::VALUE_NONE; |
|
| 242 | - |
|
| 243 | - yield 'option absent' => [ |
|
| 244 | - new InputOption( |
|
| 245 | - self::OPTION_NAME, |
|
| 246 | - null, |
|
| 247 | - $mode, |
|
| 248 | - '', |
|
| 249 | - null, // is ignored for VALUE_NONE (must be NULL) |
|
| 250 | - ), |
|
| 251 | - '', |
|
| 252 | - TypedInput::createForScalar( |
|
| 253 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "false"'), |
|
| 254 | - false, |
|
| 255 | - false, |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - new TypeException('Expected an integer. Got "false"'), |
|
| 259 | - new TypeException('Expected an integer. Got "false"'), |
|
| 260 | - new TypeException('Expected a numeric. Got "false"'), |
|
| 261 | - new TypeException('Expected a numeric. Got "false"'), |
|
| 262 | - ), |
|
| 263 | - ]; |
|
| 264 | - |
|
| 265 | - yield 'option present' => [ |
|
| 266 | - new InputOption( |
|
| 267 | - self::OPTION_NAME, |
|
| 268 | - null, |
|
| 269 | - $mode, |
|
| 270 | - '', |
|
| 271 | - null, |
|
| 272 | - ), |
|
| 273 | - '--opt', |
|
| 274 | - TypedInput::createForScalar( |
|
| 275 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "true"'), |
|
| 276 | - true, |
|
| 277 | - true, |
|
| 278 | - '1', |
|
| 279 | - '1', |
|
| 280 | - new TypeException('Expected an integer. Got "true"'), |
|
| 281 | - new TypeException('Expected an integer. Got "true"'), |
|
| 282 | - new TypeException('Expected a numeric. Got "true"'), |
|
| 283 | - new TypeException('Expected a numeric. Got "true"'), |
|
| 284 | - ), |
|
| 285 | - ]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - public static function arrayOptionProvider(): iterable |
|
| 289 | - { |
|
| 290 | - $mode = InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY; |
|
| 291 | - |
|
| 292 | - yield 'empty string' => [ |
|
| 293 | - new InputOption( |
|
| 294 | - self::OPTION_NAME, |
|
| 295 | - null, |
|
| 296 | - $mode, |
|
| 297 | - '', |
|
| 298 | - null, |
|
| 299 | - ), |
|
| 300 | - '--opt=""', |
|
| 301 | - TypedInput::createForArray( |
|
| 302 | - new TypeException( |
|
| 303 | - <<<'TXT' |
|
| 29 | + private const OPTION_NAME = 'opt'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @dataProvider requiredOptionProvider |
|
| 33 | + * @dataProvider optionalOptionProvider |
|
| 34 | + * @dataProvider noValueOptionProvider |
|
| 35 | + * @dataProvider arrayOptionProvider |
|
| 36 | + */ |
|
| 37 | + public function test_it_exposes_a_typed_api( |
|
| 38 | + InputOption $inputOption, |
|
| 39 | + string $option, |
|
| 40 | + TypedInput $expected |
|
| 41 | + ): void { |
|
| 42 | + $io = $this->getIO($inputOption, $option); |
|
| 43 | + |
|
| 44 | + TypeAssertions::assertExpectedOptionTypes( |
|
| 45 | + $expected, |
|
| 46 | + $io, |
|
| 47 | + self::OPTION_NAME, |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public static function requiredOptionProvider(): iterable |
|
| 52 | + { |
|
| 53 | + $mode = InputOption::VALUE_REQUIRED; |
|
| 54 | + |
|
| 55 | + yield 'empty string' => [ |
|
| 56 | + new InputOption( |
|
| 57 | + self::OPTION_NAME, |
|
| 58 | + null, |
|
| 59 | + $mode, |
|
| 60 | + '', |
|
| 61 | + null, |
|
| 62 | + ), |
|
| 63 | + '--opt=""', |
|
| 64 | + TypedInput::createForScalar( |
|
| 65 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'\'"'), |
|
| 66 | + false, |
|
| 67 | + false, |
|
| 68 | + '', |
|
| 69 | + '', |
|
| 70 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 71 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 72 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 73 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 74 | + ), |
|
| 75 | + ]; |
|
| 76 | + |
|
| 77 | + yield 'nominal string' => [ |
|
| 78 | + new InputOption( |
|
| 79 | + self::OPTION_NAME, |
|
| 80 | + null, |
|
| 81 | + $mode, |
|
| 82 | + '', |
|
| 83 | + null, |
|
| 84 | + ), |
|
| 85 | + '--opt=foo', |
|
| 86 | + TypedInput::createForScalar( |
|
| 87 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'foo\'"'), |
|
| 88 | + true, |
|
| 89 | + true, |
|
| 90 | + 'foo', |
|
| 91 | + 'foo', |
|
| 92 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 93 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 94 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 95 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 96 | + ), |
|
| 97 | + ]; |
|
| 98 | + |
|
| 99 | + yield 'null string' => [ |
|
| 100 | + new InputOption( |
|
| 101 | + self::OPTION_NAME, |
|
| 102 | + null, |
|
| 103 | + $mode, |
|
| 104 | + '', |
|
| 105 | + null, |
|
| 106 | + ), |
|
| 107 | + '--opt=null', |
|
| 108 | + TypedInput::createForScalar( |
|
| 109 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'null\'"'), |
|
| 110 | + true, |
|
| 111 | + true, |
|
| 112 | + 'null', |
|
| 113 | + 'null', |
|
| 114 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 115 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 116 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 117 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 118 | + ), |
|
| 119 | + ]; |
|
| 120 | + |
|
| 121 | + yield 'integer string' => [ |
|
| 122 | + new InputOption( |
|
| 123 | + self::OPTION_NAME, |
|
| 124 | + null, |
|
| 125 | + $mode, |
|
| 126 | + '', |
|
| 127 | + null, |
|
| 128 | + ), |
|
| 129 | + '--opt=10', |
|
| 130 | + TypedInput::createForScalar( |
|
| 131 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10\'"'), |
|
| 132 | + true, |
|
| 133 | + true, |
|
| 134 | + '10', |
|
| 135 | + '10', |
|
| 136 | + 10, |
|
| 137 | + 10, |
|
| 138 | + 10., |
|
| 139 | + 10., |
|
| 140 | + ), |
|
| 141 | + ]; |
|
| 142 | + |
|
| 143 | + // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 144 | + |
|
| 145 | + yield 'zero integer string' => [ |
|
| 146 | + new InputOption( |
|
| 147 | + self::OPTION_NAME, |
|
| 148 | + null, |
|
| 149 | + $mode, |
|
| 150 | + '', |
|
| 151 | + null, |
|
| 152 | + ), |
|
| 153 | + '--opt=0', |
|
| 154 | + TypedInput::createForScalar( |
|
| 155 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0\'"'), |
|
| 156 | + false, |
|
| 157 | + false, |
|
| 158 | + '0', |
|
| 159 | + '0', |
|
| 160 | + 0, |
|
| 161 | + 0, |
|
| 162 | + 0., |
|
| 163 | + 0., |
|
| 164 | + ), |
|
| 165 | + ]; |
|
| 166 | + |
|
| 167 | + yield 'float string' => [ |
|
| 168 | + new InputOption( |
|
| 169 | + self::OPTION_NAME, |
|
| 170 | + null, |
|
| 171 | + $mode, |
|
| 172 | + '', |
|
| 173 | + null, |
|
| 174 | + ), |
|
| 175 | + '--opt=10.8', |
|
| 176 | + TypedInput::createForScalar( |
|
| 177 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10.8\'"'), |
|
| 178 | + true, |
|
| 179 | + true, |
|
| 180 | + '10.8', |
|
| 181 | + '10.8', |
|
| 182 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 183 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 184 | + 10.8, |
|
| 185 | + 10.8, |
|
| 186 | + ), |
|
| 187 | + ]; |
|
| 188 | + |
|
| 189 | + // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 190 | + |
|
| 191 | + yield 'zero float string' => [ |
|
| 192 | + new InputOption( |
|
| 193 | + self::OPTION_NAME, |
|
| 194 | + null, |
|
| 195 | + $mode, |
|
| 196 | + '', |
|
| 197 | + null, |
|
| 198 | + ), |
|
| 199 | + '--opt=0.', |
|
| 200 | + TypedInput::createForScalar( |
|
| 201 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0.\'"'), |
|
| 202 | + true, |
|
| 203 | + true, |
|
| 204 | + '0.', |
|
| 205 | + '0.', |
|
| 206 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 207 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 208 | + 0., |
|
| 209 | + 0., |
|
| 210 | + ), |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + public static function optionalOptionProvider(): iterable |
|
| 215 | + { |
|
| 216 | + yield 'empty string' => [ |
|
| 217 | + new InputOption( |
|
| 218 | + self::OPTION_NAME, |
|
| 219 | + null, |
|
| 220 | + InputOption::VALUE_OPTIONAL, |
|
| 221 | + '', |
|
| 222 | + null, |
|
| 223 | + ), |
|
| 224 | + '', |
|
| 225 | + TypedInput::createForScalar( |
|
| 226 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "NULL"'), |
|
| 227 | + false, |
|
| 228 | + null, |
|
| 229 | + '', |
|
| 230 | + null, |
|
| 231 | + new TypeException('Expected an integer. Got "NULL"'), |
|
| 232 | + null, |
|
| 233 | + new TypeException('Expected a numeric. Got "NULL"'), |
|
| 234 | + null, |
|
| 235 | + ), |
|
| 236 | + ]; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public static function noValueOptionProvider(): iterable |
|
| 240 | + { |
|
| 241 | + $mode = InputOption::VALUE_NONE; |
|
| 242 | + |
|
| 243 | + yield 'option absent' => [ |
|
| 244 | + new InputOption( |
|
| 245 | + self::OPTION_NAME, |
|
| 246 | + null, |
|
| 247 | + $mode, |
|
| 248 | + '', |
|
| 249 | + null, // is ignored for VALUE_NONE (must be NULL) |
|
| 250 | + ), |
|
| 251 | + '', |
|
| 252 | + TypedInput::createForScalar( |
|
| 253 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "false"'), |
|
| 254 | + false, |
|
| 255 | + false, |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + new TypeException('Expected an integer. Got "false"'), |
|
| 259 | + new TypeException('Expected an integer. Got "false"'), |
|
| 260 | + new TypeException('Expected a numeric. Got "false"'), |
|
| 261 | + new TypeException('Expected a numeric. Got "false"'), |
|
| 262 | + ), |
|
| 263 | + ]; |
|
| 264 | + |
|
| 265 | + yield 'option present' => [ |
|
| 266 | + new InputOption( |
|
| 267 | + self::OPTION_NAME, |
|
| 268 | + null, |
|
| 269 | + $mode, |
|
| 270 | + '', |
|
| 271 | + null, |
|
| 272 | + ), |
|
| 273 | + '--opt', |
|
| 274 | + TypedInput::createForScalar( |
|
| 275 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "true"'), |
|
| 276 | + true, |
|
| 277 | + true, |
|
| 278 | + '1', |
|
| 279 | + '1', |
|
| 280 | + new TypeException('Expected an integer. Got "true"'), |
|
| 281 | + new TypeException('Expected an integer. Got "true"'), |
|
| 282 | + new TypeException('Expected a numeric. Got "true"'), |
|
| 283 | + new TypeException('Expected a numeric. Got "true"'), |
|
| 284 | + ), |
|
| 285 | + ]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + public static function arrayOptionProvider(): iterable |
|
| 289 | + { |
|
| 290 | + $mode = InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY; |
|
| 291 | + |
|
| 292 | + yield 'empty string' => [ |
|
| 293 | + new InputOption( |
|
| 294 | + self::OPTION_NAME, |
|
| 295 | + null, |
|
| 296 | + $mode, |
|
| 297 | + '', |
|
| 298 | + null, |
|
| 299 | + ), |
|
| 300 | + '--opt=""', |
|
| 301 | + TypedInput::createForArray( |
|
| 302 | + new TypeException( |
|
| 303 | + <<<'TXT' |
|
| 304 | 304 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 305 | 305 | 0 => '', |
| 306 | 306 | )" |
| 307 | 307 | TXT, |
| 308 | - ), |
|
| 309 | - [''], |
|
| 310 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 311 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 312 | - ), |
|
| 313 | - ]; |
|
| 314 | - |
|
| 315 | - yield 'single element string' => [ |
|
| 316 | - new InputOption( |
|
| 317 | - self::OPTION_NAME, |
|
| 318 | - null, |
|
| 319 | - $mode, |
|
| 320 | - '', |
|
| 321 | - null, |
|
| 322 | - ), |
|
| 323 | - '--opt=foo', |
|
| 324 | - TypedInput::createForArray( |
|
| 325 | - new TypeException( |
|
| 326 | - <<<'TXT' |
|
| 308 | + ), |
|
| 309 | + [''], |
|
| 310 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 311 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 312 | + ), |
|
| 313 | + ]; |
|
| 314 | + |
|
| 315 | + yield 'single element string' => [ |
|
| 316 | + new InputOption( |
|
| 317 | + self::OPTION_NAME, |
|
| 318 | + null, |
|
| 319 | + $mode, |
|
| 320 | + '', |
|
| 321 | + null, |
|
| 322 | + ), |
|
| 323 | + '--opt=foo', |
|
| 324 | + TypedInput::createForArray( |
|
| 325 | + new TypeException( |
|
| 326 | + <<<'TXT' |
|
| 327 | 327 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 328 | 328 | 0 => 'foo', |
| 329 | 329 | )" |
| 330 | 330 | TXT, |
| 331 | - ), |
|
| 332 | - ['foo'], |
|
| 333 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 334 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 335 | - ), |
|
| 336 | - ]; |
|
| 337 | - |
|
| 338 | - yield 'multiple elements string' => [ |
|
| 339 | - new InputOption( |
|
| 340 | - self::OPTION_NAME, |
|
| 341 | - null, |
|
| 342 | - $mode, |
|
| 343 | - '', |
|
| 344 | - null, |
|
| 345 | - ), |
|
| 346 | - '--opt=foo --opt=bar --opt=baz', |
|
| 347 | - TypedInput::createForArray( |
|
| 348 | - new TypeException( |
|
| 349 | - <<<'TXT' |
|
| 331 | + ), |
|
| 332 | + ['foo'], |
|
| 333 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 334 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 335 | + ), |
|
| 336 | + ]; |
|
| 337 | + |
|
| 338 | + yield 'multiple elements string' => [ |
|
| 339 | + new InputOption( |
|
| 340 | + self::OPTION_NAME, |
|
| 341 | + null, |
|
| 342 | + $mode, |
|
| 343 | + '', |
|
| 344 | + null, |
|
| 345 | + ), |
|
| 346 | + '--opt=foo --opt=bar --opt=baz', |
|
| 347 | + TypedInput::createForArray( |
|
| 348 | + new TypeException( |
|
| 349 | + <<<'TXT' |
|
| 350 | 350 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 351 | 351 | 0 => 'foo', |
| 352 | 352 | 1 => 'bar', |
| 353 | 353 | 2 => 'baz', |
| 354 | 354 | )" |
| 355 | 355 | TXT, |
| 356 | - ), |
|
| 357 | - ['foo', 'bar', 'baz'], |
|
| 358 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 359 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 360 | - ), |
|
| 361 | - ]; |
|
| 362 | - |
|
| 363 | - yield 'null string' => [ |
|
| 364 | - new InputOption( |
|
| 365 | - self::OPTION_NAME, |
|
| 366 | - null, |
|
| 367 | - $mode, |
|
| 368 | - '', |
|
| 369 | - null, |
|
| 370 | - ), |
|
| 371 | - '--opt=null', |
|
| 372 | - TypedInput::createForArray( |
|
| 373 | - new TypeException( |
|
| 374 | - <<<'TXT' |
|
| 356 | + ), |
|
| 357 | + ['foo', 'bar', 'baz'], |
|
| 358 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 359 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 360 | + ), |
|
| 361 | + ]; |
|
| 362 | + |
|
| 363 | + yield 'null string' => [ |
|
| 364 | + new InputOption( |
|
| 365 | + self::OPTION_NAME, |
|
| 366 | + null, |
|
| 367 | + $mode, |
|
| 368 | + '', |
|
| 369 | + null, |
|
| 370 | + ), |
|
| 371 | + '--opt=null', |
|
| 372 | + TypedInput::createForArray( |
|
| 373 | + new TypeException( |
|
| 374 | + <<<'TXT' |
|
| 375 | 375 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 376 | 376 | 0 => 'null', |
| 377 | 377 | )" |
| 378 | 378 | TXT, |
| 379 | - ), |
|
| 380 | - ['null'], |
|
| 381 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 382 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 383 | - ), |
|
| 384 | - ]; |
|
| 385 | - |
|
| 386 | - yield 'integer string' => [ |
|
| 387 | - new InputOption( |
|
| 388 | - self::OPTION_NAME, |
|
| 389 | - null, |
|
| 390 | - $mode, |
|
| 391 | - '', |
|
| 392 | - null, |
|
| 393 | - ), |
|
| 394 | - '--opt=10', |
|
| 395 | - TypedInput::createForArray( |
|
| 396 | - new TypeException( |
|
| 397 | - <<<'TXT' |
|
| 379 | + ), |
|
| 380 | + ['null'], |
|
| 381 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 382 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 383 | + ), |
|
| 384 | + ]; |
|
| 385 | + |
|
| 386 | + yield 'integer string' => [ |
|
| 387 | + new InputOption( |
|
| 388 | + self::OPTION_NAME, |
|
| 389 | + null, |
|
| 390 | + $mode, |
|
| 391 | + '', |
|
| 392 | + null, |
|
| 393 | + ), |
|
| 394 | + '--opt=10', |
|
| 395 | + TypedInput::createForArray( |
|
| 396 | + new TypeException( |
|
| 397 | + <<<'TXT' |
|
| 398 | 398 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 399 | 399 | 0 => '10', |
| 400 | 400 | )" |
| 401 | 401 | TXT, |
| 402 | - ), |
|
| 403 | - ['10'], |
|
| 404 | - [10], |
|
| 405 | - [10.], |
|
| 406 | - ), |
|
| 407 | - ]; |
|
| 408 | - |
|
| 409 | - // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 410 | - |
|
| 411 | - yield 'zero integer string' => [ |
|
| 412 | - new InputOption( |
|
| 413 | - self::OPTION_NAME, |
|
| 414 | - null, |
|
| 415 | - $mode, |
|
| 416 | - '', |
|
| 417 | - null, |
|
| 418 | - ), |
|
| 419 | - '--opt=0', |
|
| 420 | - TypedInput::createForArray( |
|
| 421 | - new TypeException( |
|
| 422 | - <<<'TXT' |
|
| 402 | + ), |
|
| 403 | + ['10'], |
|
| 404 | + [10], |
|
| 405 | + [10.], |
|
| 406 | + ), |
|
| 407 | + ]; |
|
| 408 | + |
|
| 409 | + // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 410 | + |
|
| 411 | + yield 'zero integer string' => [ |
|
| 412 | + new InputOption( |
|
| 413 | + self::OPTION_NAME, |
|
| 414 | + null, |
|
| 415 | + $mode, |
|
| 416 | + '', |
|
| 417 | + null, |
|
| 418 | + ), |
|
| 419 | + '--opt=0', |
|
| 420 | + TypedInput::createForArray( |
|
| 421 | + new TypeException( |
|
| 422 | + <<<'TXT' |
|
| 423 | 423 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 424 | 424 | 0 => '0', |
| 425 | 425 | )" |
| 426 | 426 | TXT, |
| 427 | - ), |
|
| 428 | - ['0'], |
|
| 429 | - [0], |
|
| 430 | - [0.], |
|
| 431 | - ), |
|
| 432 | - ]; |
|
| 433 | - |
|
| 434 | - yield 'float string' => [ |
|
| 435 | - new InputOption( |
|
| 436 | - self::OPTION_NAME, |
|
| 437 | - null, |
|
| 438 | - $mode, |
|
| 439 | - '', |
|
| 440 | - null, |
|
| 441 | - ), |
|
| 442 | - '--opt=10.8', |
|
| 443 | - TypedInput::createForArray( |
|
| 444 | - new TypeException( |
|
| 445 | - <<<'TXT' |
|
| 427 | + ), |
|
| 428 | + ['0'], |
|
| 429 | + [0], |
|
| 430 | + [0.], |
|
| 431 | + ), |
|
| 432 | + ]; |
|
| 433 | + |
|
| 434 | + yield 'float string' => [ |
|
| 435 | + new InputOption( |
|
| 436 | + self::OPTION_NAME, |
|
| 437 | + null, |
|
| 438 | + $mode, |
|
| 439 | + '', |
|
| 440 | + null, |
|
| 441 | + ), |
|
| 442 | + '--opt=10.8', |
|
| 443 | + TypedInput::createForArray( |
|
| 444 | + new TypeException( |
|
| 445 | + <<<'TXT' |
|
| 446 | 446 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 447 | 447 | 0 => '10.8', |
| 448 | 448 | )" |
| 449 | 449 | TXT, |
| 450 | - ), |
|
| 451 | - ['10.8'], |
|
| 452 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 453 | - [10.8], |
|
| 454 | - ), |
|
| 455 | - ]; |
|
| 456 | - |
|
| 457 | - // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 458 | - |
|
| 459 | - yield 'zero float string' => [ |
|
| 460 | - new InputOption( |
|
| 461 | - self::OPTION_NAME, |
|
| 462 | - null, |
|
| 463 | - $mode, |
|
| 464 | - '', |
|
| 465 | - null, |
|
| 466 | - ), |
|
| 467 | - '--opt=0.', |
|
| 468 | - TypedInput::createForArray( |
|
| 469 | - new TypeException( |
|
| 470 | - <<<'TXT' |
|
| 450 | + ), |
|
| 451 | + ['10.8'], |
|
| 452 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 453 | + [10.8], |
|
| 454 | + ), |
|
| 455 | + ]; |
|
| 456 | + |
|
| 457 | + // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 458 | + |
|
| 459 | + yield 'zero float string' => [ |
|
| 460 | + new InputOption( |
|
| 461 | + self::OPTION_NAME, |
|
| 462 | + null, |
|
| 463 | + $mode, |
|
| 464 | + '', |
|
| 465 | + null, |
|
| 466 | + ), |
|
| 467 | + '--opt=0.', |
|
| 468 | + TypedInput::createForArray( |
|
| 469 | + new TypeException( |
|
| 470 | + <<<'TXT' |
|
| 471 | 471 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 472 | 472 | 0 => '0.', |
| 473 | 473 | )" |
| 474 | 474 | TXT, |
| 475 | - ), |
|
| 476 | - ['0.'], |
|
| 477 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 478 | - [0.], |
|
| 479 | - ), |
|
| 480 | - ]; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - private function getIO( |
|
| 484 | - InputOption $inputOption, |
|
| 485 | - string $option |
|
| 486 | - ): IO { |
|
| 487 | - $application = new Application(); |
|
| 488 | - $application->add( |
|
| 489 | - new DynamicCommandWithOptions($inputOption), |
|
| 490 | - ); |
|
| 491 | - |
|
| 492 | - $input = new StringInput('app:input:opts '.$option); |
|
| 493 | - $input->setInteractive(false); |
|
| 494 | - |
|
| 495 | - $application->doRun( |
|
| 496 | - $input, |
|
| 497 | - new NullOutput(), |
|
| 498 | - ); |
|
| 499 | - |
|
| 500 | - $command = $application->find('app:input:opts'); |
|
| 501 | - self::assertInstanceOf(DynamicCommandWithOptions::class, $command); |
|
| 502 | - |
|
| 503 | - return new IO( |
|
| 504 | - $command->input, |
|
| 505 | - new NullOutput(), |
|
| 506 | - ); |
|
| 507 | - } |
|
| 475 | + ), |
|
| 476 | + ['0.'], |
|
| 477 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 478 | + [0.], |
|
| 479 | + ), |
|
| 480 | + ]; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + private function getIO( |
|
| 484 | + InputOption $inputOption, |
|
| 485 | + string $option |
|
| 486 | + ): IO { |
|
| 487 | + $application = new Application(); |
|
| 488 | + $application->add( |
|
| 489 | + new DynamicCommandWithOptions($inputOption), |
|
| 490 | + ); |
|
| 491 | + |
|
| 492 | + $input = new StringInput('app:input:opts '.$option); |
|
| 493 | + $input->setInteractive(false); |
|
| 494 | + |
|
| 495 | + $application->doRun( |
|
| 496 | + $input, |
|
| 497 | + new NullOutput(), |
|
| 498 | + ); |
|
| 499 | + |
|
| 500 | + $command = $application->find('app:input:opts'); |
|
| 501 | + self::assertInstanceOf(DynamicCommandWithOptions::class, $command); |
|
| 502 | + |
|
| 503 | + return new IO( |
|
| 504 | + $command->input, |
|
| 505 | + new NullOutput(), |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | 508 | } |
@@ -246,7 +246,7 @@ |
||
| 246 | 246 | null, |
| 247 | 247 | $mode, |
| 248 | 248 | '', |
| 249 | - null, // is ignored for VALUE_NONE (must be NULL) |
|
| 249 | + null, // is ignored for VALUE_NONE (must be NULL) |
|
| 250 | 250 | ), |
| 251 | 251 | '', |
| 252 | 252 | TypedInput::createForScalar( |
@@ -24,8 +24,7 @@ |
||
| 24 | 24 | * @covers \Fidry\Console\Command\ConsoleAssert |
| 25 | 25 | * @covers \Fidry\Console\IO |
| 26 | 26 | */ |
| 27 | -final class IOOptionsTest extends TestCase |
|
| 28 | -{ |
|
| 27 | +final class IOOptionsTest extends TestCase { |
|
| 29 | 28 | private const OPTION_NAME = 'opt'; |
| 30 | 29 | |
| 31 | 30 | /** |
@@ -21,22 +21,22 @@ |
||
| 21 | 21 | |
| 22 | 22 | final class DynamicCommandWithOptions extends Command |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @psalm-suppress PropertyNotSetInConstructor |
|
| 26 | - */ |
|
| 27 | - public InputInterface $input; |
|
| 24 | + /** |
|
| 25 | + * @psalm-suppress PropertyNotSetInConstructor |
|
| 26 | + */ |
|
| 27 | + public InputInterface $input; |
|
| 28 | 28 | |
| 29 | - public function __construct(InputOption $inputOption) |
|
| 30 | - { |
|
| 31 | - parent::__construct('app:input:opts'); |
|
| 29 | + public function __construct(InputOption $inputOption) |
|
| 30 | + { |
|
| 31 | + parent::__construct('app:input:opts'); |
|
| 32 | 32 | |
| 33 | - $this->getDefinition()->addOption($inputOption); |
|
| 34 | - } |
|
| 33 | + $this->getDefinition()->addOption($inputOption); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 37 | - { |
|
| 38 | - $this->input = $input; |
|
| 36 | + protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 37 | + { |
|
| 38 | + $this->input = $input; |
|
| 39 | 39 | |
| 40 | - return ExitCode::SUCCESS; |
|
| 41 | - } |
|
| 40 | + return ExitCode::SUCCESS; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | use Symfony\Component\Console\Input\InputOption; |
| 20 | 20 | use Symfony\Component\Console\Output\OutputInterface; |
| 21 | 21 | |
| 22 | -final class DynamicCommandWithOptions extends Command |
|
| 23 | -{ |
|
| 22 | +final class DynamicCommandWithOptions extends Command { |
|
| 24 | 23 | /** |
| 25 | 24 | * @psalm-suppress PropertyNotSetInConstructor |
| 26 | 25 | */ |
@@ -15,10 +15,10 @@ |
||
| 15 | 15 | |
| 16 | 16 | final class TypeException |
| 17 | 17 | { |
| 18 | - public string $message; |
|
| 18 | + public string $message; |
|
| 19 | 19 | |
| 20 | - public function __construct(string $message) |
|
| 21 | - { |
|
| 22 | - $this->message = $message; |
|
| 23 | - } |
|
| 20 | + public function __construct(string $message) |
|
| 21 | + { |
|
| 22 | + $this->message = $message; |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -13,8 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | namespace Fidry\Console\Tests\IO; |
| 15 | 15 | |
| 16 | -final class TypeException |
|
| 17 | -{ |
|
| 16 | +final class TypeException { |
|
| 18 | 17 | public string $message; |
| 19 | 18 | |
| 20 | 19 | public function __construct(string $message) |
@@ -20,142 +20,142 @@ |
||
| 20 | 20 | |
| 21 | 21 | final class TypeAssertions |
| 22 | 22 | { |
| 23 | - private function __construct() |
|
| 24 | - { |
|
| 25 | - } |
|
| 23 | + private function __construct() |
|
| 24 | + { |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public static function assertExpectedArgumentTypes( |
|
| 28 | - TypedInput $expected, |
|
| 29 | - IO $io, |
|
| 30 | - string $argumentName |
|
| 31 | - ): void { |
|
| 32 | - self::assertExpectedType( |
|
| 33 | - $expected->boolean, |
|
| 34 | - static fn () => $io->getBooleanArgument($argumentName), |
|
| 35 | - ); |
|
| 36 | - self::assertExpectedType( |
|
| 37 | - $expected->nullableBoolean, |
|
| 38 | - static fn () => $io->getNullableBooleanArgument($argumentName), |
|
| 39 | - ); |
|
| 40 | - self::assertExpectedType( |
|
| 41 | - $expected->string, |
|
| 42 | - static fn () => $io->getStringArgument($argumentName), |
|
| 43 | - ); |
|
| 44 | - self::assertExpectedType( |
|
| 45 | - $expected->nullableString, |
|
| 46 | - static fn () => $io->getNullableStringArgument($argumentName), |
|
| 47 | - ); |
|
| 48 | - self::assertExpectedType( |
|
| 49 | - $expected->stringArray, |
|
| 50 | - static fn () => $io->getStringArrayArgument($argumentName), |
|
| 51 | - ); |
|
| 52 | - self::assertExpectedType( |
|
| 53 | - $expected->integer, |
|
| 54 | - static fn () => $io->getIntegerArgument($argumentName), |
|
| 55 | - ); |
|
| 56 | - self::assertExpectedType( |
|
| 57 | - $expected->nullableInteger, |
|
| 58 | - static fn () => $io->getNullableIntegerArgument($argumentName), |
|
| 59 | - ); |
|
| 60 | - self::assertExpectedType( |
|
| 61 | - $expected->integerArray, |
|
| 62 | - static fn () => $io->getIntegerArrayArgument($argumentName), |
|
| 63 | - ); |
|
| 64 | - self::assertExpectedType( |
|
| 65 | - $expected->float, |
|
| 66 | - static fn () => $io->getFloatArgument($argumentName), |
|
| 67 | - ); |
|
| 68 | - self::assertExpectedType( |
|
| 69 | - $expected->nullableFloat, |
|
| 70 | - static fn () => $io->getNullableFloatArgument($argumentName), |
|
| 71 | - ); |
|
| 72 | - self::assertExpectedType( |
|
| 73 | - $expected->floatArray, |
|
| 74 | - static fn () => $io->getFloatArrayArgument($argumentName), |
|
| 75 | - ); |
|
| 76 | - } |
|
| 27 | + public static function assertExpectedArgumentTypes( |
|
| 28 | + TypedInput $expected, |
|
| 29 | + IO $io, |
|
| 30 | + string $argumentName |
|
| 31 | + ): void { |
|
| 32 | + self::assertExpectedType( |
|
| 33 | + $expected->boolean, |
|
| 34 | + static fn () => $io->getBooleanArgument($argumentName), |
|
| 35 | + ); |
|
| 36 | + self::assertExpectedType( |
|
| 37 | + $expected->nullableBoolean, |
|
| 38 | + static fn () => $io->getNullableBooleanArgument($argumentName), |
|
| 39 | + ); |
|
| 40 | + self::assertExpectedType( |
|
| 41 | + $expected->string, |
|
| 42 | + static fn () => $io->getStringArgument($argumentName), |
|
| 43 | + ); |
|
| 44 | + self::assertExpectedType( |
|
| 45 | + $expected->nullableString, |
|
| 46 | + static fn () => $io->getNullableStringArgument($argumentName), |
|
| 47 | + ); |
|
| 48 | + self::assertExpectedType( |
|
| 49 | + $expected->stringArray, |
|
| 50 | + static fn () => $io->getStringArrayArgument($argumentName), |
|
| 51 | + ); |
|
| 52 | + self::assertExpectedType( |
|
| 53 | + $expected->integer, |
|
| 54 | + static fn () => $io->getIntegerArgument($argumentName), |
|
| 55 | + ); |
|
| 56 | + self::assertExpectedType( |
|
| 57 | + $expected->nullableInteger, |
|
| 58 | + static fn () => $io->getNullableIntegerArgument($argumentName), |
|
| 59 | + ); |
|
| 60 | + self::assertExpectedType( |
|
| 61 | + $expected->integerArray, |
|
| 62 | + static fn () => $io->getIntegerArrayArgument($argumentName), |
|
| 63 | + ); |
|
| 64 | + self::assertExpectedType( |
|
| 65 | + $expected->float, |
|
| 66 | + static fn () => $io->getFloatArgument($argumentName), |
|
| 67 | + ); |
|
| 68 | + self::assertExpectedType( |
|
| 69 | + $expected->nullableFloat, |
|
| 70 | + static fn () => $io->getNullableFloatArgument($argumentName), |
|
| 71 | + ); |
|
| 72 | + self::assertExpectedType( |
|
| 73 | + $expected->floatArray, |
|
| 74 | + static fn () => $io->getFloatArrayArgument($argumentName), |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public static function assertExpectedOptionTypes( |
|
| 79 | - TypedInput $expected, |
|
| 80 | - IO $io, |
|
| 81 | - string $optionName |
|
| 82 | - ): void { |
|
| 83 | - self::assertExpectedType( |
|
| 84 | - $expected->boolean, |
|
| 85 | - static fn () => $io->getBooleanOption($optionName), |
|
| 86 | - ); |
|
| 87 | - self::assertExpectedType( |
|
| 88 | - $expected->nullableBoolean, |
|
| 89 | - static fn () => $io->getNullableBooleanOption($optionName), |
|
| 90 | - ); |
|
| 91 | - self::assertExpectedType( |
|
| 92 | - $expected->string, |
|
| 93 | - static fn () => $io->getStringOption($optionName), |
|
| 94 | - ); |
|
| 95 | - self::assertExpectedType( |
|
| 96 | - $expected->nullableString, |
|
| 97 | - static fn () => $io->getNullableStringOption($optionName), |
|
| 98 | - ); |
|
| 99 | - self::assertExpectedType( |
|
| 100 | - $expected->stringArray, |
|
| 101 | - static fn () => $io->getStringArrayOption($optionName), |
|
| 102 | - ); |
|
| 103 | - self::assertExpectedType( |
|
| 104 | - $expected->integer, |
|
| 105 | - static fn () => $io->getIntegerOption($optionName), |
|
| 106 | - ); |
|
| 107 | - self::assertExpectedType( |
|
| 108 | - $expected->nullableInteger, |
|
| 109 | - static fn () => $io->getNullableIntegerOption($optionName), |
|
| 110 | - ); |
|
| 111 | - self::assertExpectedType( |
|
| 112 | - $expected->integerArray, |
|
| 113 | - static fn () => $io->getIntegerArrayOption($optionName), |
|
| 114 | - ); |
|
| 115 | - self::assertExpectedType( |
|
| 116 | - $expected->float, |
|
| 117 | - static fn () => $io->getFloatOption($optionName), |
|
| 118 | - ); |
|
| 119 | - self::assertExpectedType( |
|
| 120 | - $expected->nullableFloat, |
|
| 121 | - static fn () => $io->getNullableFloatOption($optionName), |
|
| 122 | - ); |
|
| 123 | - self::assertExpectedType( |
|
| 124 | - $expected->floatArray, |
|
| 125 | - static fn () => $io->getFloatArrayOption($optionName), |
|
| 126 | - ); |
|
| 127 | - } |
|
| 78 | + public static function assertExpectedOptionTypes( |
|
| 79 | + TypedInput $expected, |
|
| 80 | + IO $io, |
|
| 81 | + string $optionName |
|
| 82 | + ): void { |
|
| 83 | + self::assertExpectedType( |
|
| 84 | + $expected->boolean, |
|
| 85 | + static fn () => $io->getBooleanOption($optionName), |
|
| 86 | + ); |
|
| 87 | + self::assertExpectedType( |
|
| 88 | + $expected->nullableBoolean, |
|
| 89 | + static fn () => $io->getNullableBooleanOption($optionName), |
|
| 90 | + ); |
|
| 91 | + self::assertExpectedType( |
|
| 92 | + $expected->string, |
|
| 93 | + static fn () => $io->getStringOption($optionName), |
|
| 94 | + ); |
|
| 95 | + self::assertExpectedType( |
|
| 96 | + $expected->nullableString, |
|
| 97 | + static fn () => $io->getNullableStringOption($optionName), |
|
| 98 | + ); |
|
| 99 | + self::assertExpectedType( |
|
| 100 | + $expected->stringArray, |
|
| 101 | + static fn () => $io->getStringArrayOption($optionName), |
|
| 102 | + ); |
|
| 103 | + self::assertExpectedType( |
|
| 104 | + $expected->integer, |
|
| 105 | + static fn () => $io->getIntegerOption($optionName), |
|
| 106 | + ); |
|
| 107 | + self::assertExpectedType( |
|
| 108 | + $expected->nullableInteger, |
|
| 109 | + static fn () => $io->getNullableIntegerOption($optionName), |
|
| 110 | + ); |
|
| 111 | + self::assertExpectedType( |
|
| 112 | + $expected->integerArray, |
|
| 113 | + static fn () => $io->getIntegerArrayOption($optionName), |
|
| 114 | + ); |
|
| 115 | + self::assertExpectedType( |
|
| 116 | + $expected->float, |
|
| 117 | + static fn () => $io->getFloatOption($optionName), |
|
| 118 | + ); |
|
| 119 | + self::assertExpectedType( |
|
| 120 | + $expected->nullableFloat, |
|
| 121 | + static fn () => $io->getNullableFloatOption($optionName), |
|
| 122 | + ); |
|
| 123 | + self::assertExpectedType( |
|
| 124 | + $expected->floatArray, |
|
| 125 | + static fn () => $io->getFloatArrayOption($optionName), |
|
| 126 | + ); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @param mixed|TypeException $expected |
|
| 131 | - * @param callable():mixed $getArgument |
|
| 132 | - */ |
|
| 133 | - private static function assertExpectedType($expected, callable $getArgument): void |
|
| 134 | - { |
|
| 135 | - try { |
|
| 136 | - $actual = $getArgument(); |
|
| 129 | + /** |
|
| 130 | + * @param mixed|TypeException $expected |
|
| 131 | + * @param callable():mixed $getArgument |
|
| 132 | + */ |
|
| 133 | + private static function assertExpectedType($expected, callable $getArgument): void |
|
| 134 | + { |
|
| 135 | + try { |
|
| 136 | + $actual = $getArgument(); |
|
| 137 | 137 | |
| 138 | - if ($expected instanceof TypeException) { |
|
| 139 | - Assert::fail( |
|
| 140 | - sprintf( |
|
| 141 | - 'Expected a type exception to be thrown with the message "%s"', |
|
| 142 | - $expected->message, |
|
| 143 | - ), |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - } catch (ConsoleInvalidArgumentException $exception) { |
|
| 147 | - if ($expected instanceof TypeException) { |
|
| 148 | - Assert::assertSame( |
|
| 149 | - $expected->message, |
|
| 150 | - $exception->getMessage(), |
|
| 151 | - ); |
|
| 138 | + if ($expected instanceof TypeException) { |
|
| 139 | + Assert::fail( |
|
| 140 | + sprintf( |
|
| 141 | + 'Expected a type exception to be thrown with the message "%s"', |
|
| 142 | + $expected->message, |
|
| 143 | + ), |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + } catch (ConsoleInvalidArgumentException $exception) { |
|
| 147 | + if ($expected instanceof TypeException) { |
|
| 148 | + Assert::assertSame( |
|
| 149 | + $expected->message, |
|
| 150 | + $exception->getMessage(), |
|
| 151 | + ); |
|
| 152 | 152 | |
| 153 | - return; |
|
| 154 | - } |
|
| 153 | + return; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - throw $exception; |
|
| 157 | - } |
|
| 156 | + throw $exception; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - Assert::assertSame($expected, $actual); |
|
| 160 | - } |
|
| 159 | + Assert::assertSame($expected, $actual); |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -18,8 +18,7 @@ |
||
| 18 | 18 | use function Safe\sprintf; |
| 19 | 19 | use Symfony\Component\Console\Exception\InvalidArgumentException as ConsoleInvalidArgumentException; |
| 20 | 20 | |
| 21 | -final class TypeAssertions |
|
| 22 | -{ |
|
| 21 | +final class TypeAssertions { |
|
| 23 | 22 | private function __construct() |
| 24 | 23 | { |
| 25 | 24 | } |
@@ -15,159 +15,159 @@ |
||
| 15 | 15 | |
| 16 | 16 | final class TypedInput |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var bool|TypeException |
|
| 20 | - */ |
|
| 21 | - public $boolean; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var null|bool|TypeException |
|
| 25 | - */ |
|
| 26 | - public $nullableBoolean; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string|TypeException |
|
| 30 | - */ |
|
| 31 | - public $string; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var null|string|TypeException |
|
| 35 | - */ |
|
| 36 | - public $nullableString; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string[]|TypeException |
|
| 40 | - */ |
|
| 41 | - public $stringArray; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var int|TypeException |
|
| 45 | - */ |
|
| 46 | - public $integer; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var null|int|TypeException |
|
| 50 | - */ |
|
| 51 | - public $nullableInteger; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var int[]|TypeException |
|
| 55 | - */ |
|
| 56 | - public $integerArray; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var float|TypeException |
|
| 60 | - */ |
|
| 61 | - public $float; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var null|float|TypeException |
|
| 65 | - */ |
|
| 66 | - public $nullableFloat; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var float[]|TypeException |
|
| 70 | - */ |
|
| 71 | - public $floatArray; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param bool|TypeException $boolean |
|
| 75 | - * @param null|bool|TypeException $nullableBoolean |
|
| 76 | - * @param string|TypeException $string |
|
| 77 | - * @param null|string|TypeException $nullableString |
|
| 78 | - * @param string[]|TypeException $stringArray |
|
| 79 | - * @param int|TypeException $integer |
|
| 80 | - * @param null|int|TypeException $nullableInteger |
|
| 81 | - * @param int[]|TypeException $integerArray |
|
| 82 | - * @param float|TypeException $float |
|
| 83 | - * @param null|float|TypeException $nullableFloat |
|
| 84 | - * @param float[]|TypeException $floatArray |
|
| 85 | - */ |
|
| 86 | - public function __construct( |
|
| 87 | - $boolean, |
|
| 88 | - $nullableBoolean, |
|
| 89 | - $string, |
|
| 90 | - $nullableString, |
|
| 91 | - $stringArray, |
|
| 92 | - $integer, |
|
| 93 | - $nullableInteger, |
|
| 94 | - $integerArray, |
|
| 95 | - $float, |
|
| 96 | - $nullableFloat, |
|
| 97 | - $floatArray |
|
| 98 | - ) { |
|
| 99 | - $this->boolean = $boolean; |
|
| 100 | - $this->nullableBoolean = $nullableBoolean; |
|
| 101 | - $this->string = $string; |
|
| 102 | - $this->nullableString = $nullableString; |
|
| 103 | - $this->stringArray = $stringArray; |
|
| 104 | - $this->integer = $integer; |
|
| 105 | - $this->nullableInteger = $nullableInteger; |
|
| 106 | - $this->integerArray = $integerArray; |
|
| 107 | - $this->float = $float; |
|
| 108 | - $this->nullableFloat = $nullableFloat; |
|
| 109 | - $this->floatArray = $floatArray; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param bool|TypeException $boolean |
|
| 114 | - * @param null|bool|TypeException $nullableBoolean |
|
| 115 | - * @param string|TypeException $string |
|
| 116 | - * @param null|string|TypeException $nullableString |
|
| 117 | - * @param int|TypeException $integer |
|
| 118 | - * @param null|int|TypeException $nullableInteger |
|
| 119 | - * @param float|TypeException $float |
|
| 120 | - * @param null|float|TypeException $nullableFloat |
|
| 121 | - */ |
|
| 122 | - public static function createForScalar( |
|
| 123 | - TypeException $arrayToScalarTypeException, |
|
| 124 | - $boolean, |
|
| 125 | - $nullableBoolean, |
|
| 126 | - $string, |
|
| 127 | - $nullableString, |
|
| 128 | - $integer, |
|
| 129 | - $nullableInteger, |
|
| 130 | - $float, |
|
| 131 | - $nullableFloat |
|
| 132 | - ): self { |
|
| 133 | - return new self( |
|
| 134 | - $boolean, |
|
| 135 | - $nullableBoolean, |
|
| 136 | - $string, |
|
| 137 | - $nullableString, |
|
| 138 | - $arrayToScalarTypeException, |
|
| 139 | - $integer, |
|
| 140 | - $nullableInteger, |
|
| 141 | - $arrayToScalarTypeException, |
|
| 142 | - $float, |
|
| 143 | - $nullableFloat, |
|
| 144 | - $arrayToScalarTypeException, |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param string[]|TypeException $stringArray |
|
| 150 | - * @param int[]|TypeException $integerArray |
|
| 151 | - * @param float[]|TypeException $floatArray |
|
| 152 | - */ |
|
| 153 | - public static function createForArray( |
|
| 154 | - TypeException $scalarToArrayTypeException, |
|
| 155 | - $stringArray, |
|
| 156 | - $integerArray, |
|
| 157 | - $floatArray |
|
| 158 | - ): self { |
|
| 159 | - return new self( |
|
| 160 | - $scalarToArrayTypeException, |
|
| 161 | - $scalarToArrayTypeException, |
|
| 162 | - $scalarToArrayTypeException, |
|
| 163 | - $scalarToArrayTypeException, |
|
| 164 | - $stringArray, |
|
| 165 | - $scalarToArrayTypeException, |
|
| 166 | - $scalarToArrayTypeException, |
|
| 167 | - $integerArray, |
|
| 168 | - $scalarToArrayTypeException, |
|
| 169 | - $scalarToArrayTypeException, |
|
| 170 | - $floatArray, |
|
| 171 | - ); |
|
| 172 | - } |
|
| 18 | + /** |
|
| 19 | + * @var bool|TypeException |
|
| 20 | + */ |
|
| 21 | + public $boolean; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var null|bool|TypeException |
|
| 25 | + */ |
|
| 26 | + public $nullableBoolean; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string|TypeException |
|
| 30 | + */ |
|
| 31 | + public $string; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var null|string|TypeException |
|
| 35 | + */ |
|
| 36 | + public $nullableString; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string[]|TypeException |
|
| 40 | + */ |
|
| 41 | + public $stringArray; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var int|TypeException |
|
| 45 | + */ |
|
| 46 | + public $integer; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var null|int|TypeException |
|
| 50 | + */ |
|
| 51 | + public $nullableInteger; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var int[]|TypeException |
|
| 55 | + */ |
|
| 56 | + public $integerArray; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var float|TypeException |
|
| 60 | + */ |
|
| 61 | + public $float; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var null|float|TypeException |
|
| 65 | + */ |
|
| 66 | + public $nullableFloat; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var float[]|TypeException |
|
| 70 | + */ |
|
| 71 | + public $floatArray; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param bool|TypeException $boolean |
|
| 75 | + * @param null|bool|TypeException $nullableBoolean |
|
| 76 | + * @param string|TypeException $string |
|
| 77 | + * @param null|string|TypeException $nullableString |
|
| 78 | + * @param string[]|TypeException $stringArray |
|
| 79 | + * @param int|TypeException $integer |
|
| 80 | + * @param null|int|TypeException $nullableInteger |
|
| 81 | + * @param int[]|TypeException $integerArray |
|
| 82 | + * @param float|TypeException $float |
|
| 83 | + * @param null|float|TypeException $nullableFloat |
|
| 84 | + * @param float[]|TypeException $floatArray |
|
| 85 | + */ |
|
| 86 | + public function __construct( |
|
| 87 | + $boolean, |
|
| 88 | + $nullableBoolean, |
|
| 89 | + $string, |
|
| 90 | + $nullableString, |
|
| 91 | + $stringArray, |
|
| 92 | + $integer, |
|
| 93 | + $nullableInteger, |
|
| 94 | + $integerArray, |
|
| 95 | + $float, |
|
| 96 | + $nullableFloat, |
|
| 97 | + $floatArray |
|
| 98 | + ) { |
|
| 99 | + $this->boolean = $boolean; |
|
| 100 | + $this->nullableBoolean = $nullableBoolean; |
|
| 101 | + $this->string = $string; |
|
| 102 | + $this->nullableString = $nullableString; |
|
| 103 | + $this->stringArray = $stringArray; |
|
| 104 | + $this->integer = $integer; |
|
| 105 | + $this->nullableInteger = $nullableInteger; |
|
| 106 | + $this->integerArray = $integerArray; |
|
| 107 | + $this->float = $float; |
|
| 108 | + $this->nullableFloat = $nullableFloat; |
|
| 109 | + $this->floatArray = $floatArray; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param bool|TypeException $boolean |
|
| 114 | + * @param null|bool|TypeException $nullableBoolean |
|
| 115 | + * @param string|TypeException $string |
|
| 116 | + * @param null|string|TypeException $nullableString |
|
| 117 | + * @param int|TypeException $integer |
|
| 118 | + * @param null|int|TypeException $nullableInteger |
|
| 119 | + * @param float|TypeException $float |
|
| 120 | + * @param null|float|TypeException $nullableFloat |
|
| 121 | + */ |
|
| 122 | + public static function createForScalar( |
|
| 123 | + TypeException $arrayToScalarTypeException, |
|
| 124 | + $boolean, |
|
| 125 | + $nullableBoolean, |
|
| 126 | + $string, |
|
| 127 | + $nullableString, |
|
| 128 | + $integer, |
|
| 129 | + $nullableInteger, |
|
| 130 | + $float, |
|
| 131 | + $nullableFloat |
|
| 132 | + ): self { |
|
| 133 | + return new self( |
|
| 134 | + $boolean, |
|
| 135 | + $nullableBoolean, |
|
| 136 | + $string, |
|
| 137 | + $nullableString, |
|
| 138 | + $arrayToScalarTypeException, |
|
| 139 | + $integer, |
|
| 140 | + $nullableInteger, |
|
| 141 | + $arrayToScalarTypeException, |
|
| 142 | + $float, |
|
| 143 | + $nullableFloat, |
|
| 144 | + $arrayToScalarTypeException, |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param string[]|TypeException $stringArray |
|
| 150 | + * @param int[]|TypeException $integerArray |
|
| 151 | + * @param float[]|TypeException $floatArray |
|
| 152 | + */ |
|
| 153 | + public static function createForArray( |
|
| 154 | + TypeException $scalarToArrayTypeException, |
|
| 155 | + $stringArray, |
|
| 156 | + $integerArray, |
|
| 157 | + $floatArray |
|
| 158 | + ): self { |
|
| 159 | + return new self( |
|
| 160 | + $scalarToArrayTypeException, |
|
| 161 | + $scalarToArrayTypeException, |
|
| 162 | + $scalarToArrayTypeException, |
|
| 163 | + $scalarToArrayTypeException, |
|
| 164 | + $stringArray, |
|
| 165 | + $scalarToArrayTypeException, |
|
| 166 | + $scalarToArrayTypeException, |
|
| 167 | + $integerArray, |
|
| 168 | + $scalarToArrayTypeException, |
|
| 169 | + $scalarToArrayTypeException, |
|
| 170 | + $floatArray, |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -13,8 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | namespace Fidry\Console\Tests\IO; |
| 15 | 15 | |
| 16 | -final class TypedInput |
|
| 17 | -{ |
|
| 16 | +final class TypedInput { |
|
| 18 | 17 | /** |
| 19 | 18 | * @var bool|TypeException |
| 20 | 19 | */ |
@@ -26,417 +26,417 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | final class IOArgumentTest extends TestCase |
| 28 | 28 | { |
| 29 | - private const ARGUMENT_NAME = 'arg'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @dataProvider requiredArgumentProvider |
|
| 33 | - * @dataProvider optionalArgumentProvider |
|
| 34 | - * @dataProvider arrayArgumentProvider |
|
| 35 | - */ |
|
| 36 | - public function test_it_exposes_a_typed_api( |
|
| 37 | - InputArgument $inputArgument, |
|
| 38 | - string $argument, |
|
| 39 | - TypedInput $expected |
|
| 40 | - ): void { |
|
| 41 | - $io = $this->getIO($inputArgument, $argument); |
|
| 42 | - |
|
| 43 | - TypeAssertions::assertExpectedArgumentTypes( |
|
| 44 | - $expected, |
|
| 45 | - $io, |
|
| 46 | - self::ARGUMENT_NAME, |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public static function requiredArgumentProvider(): iterable |
|
| 51 | - { |
|
| 52 | - $mode = InputArgument::REQUIRED; |
|
| 53 | - |
|
| 54 | - yield 'empty string' => [ |
|
| 55 | - new InputArgument( |
|
| 56 | - self::ARGUMENT_NAME, |
|
| 57 | - $mode, |
|
| 58 | - '', |
|
| 59 | - null, |
|
| 60 | - ), |
|
| 61 | - '""', |
|
| 62 | - TypedInput::createForScalar( |
|
| 63 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'\'"'), |
|
| 64 | - false, |
|
| 65 | - false, |
|
| 66 | - '', |
|
| 67 | - '', |
|
| 68 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 69 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 70 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 71 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 72 | - ), |
|
| 73 | - ]; |
|
| 74 | - |
|
| 75 | - yield 'nominal string' => [ |
|
| 76 | - new InputArgument( |
|
| 77 | - self::ARGUMENT_NAME, |
|
| 78 | - $mode, |
|
| 79 | - '', |
|
| 80 | - null, |
|
| 81 | - ), |
|
| 82 | - 'foo', |
|
| 83 | - TypedInput::createForScalar( |
|
| 84 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'foo\'"'), |
|
| 85 | - true, |
|
| 86 | - true, |
|
| 87 | - 'foo', |
|
| 88 | - 'foo', |
|
| 89 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 90 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 91 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 92 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 93 | - ), |
|
| 94 | - ]; |
|
| 95 | - |
|
| 96 | - yield 'null string' => [ |
|
| 97 | - new InputArgument( |
|
| 98 | - self::ARGUMENT_NAME, |
|
| 99 | - $mode, |
|
| 100 | - '', |
|
| 101 | - null, |
|
| 102 | - ), |
|
| 103 | - 'null', |
|
| 104 | - TypedInput::createForScalar( |
|
| 105 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'null\'"'), |
|
| 106 | - true, |
|
| 107 | - true, |
|
| 108 | - 'null', |
|
| 109 | - 'null', |
|
| 110 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 111 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 112 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 113 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 114 | - ), |
|
| 115 | - ]; |
|
| 116 | - |
|
| 117 | - yield 'integer string' => [ |
|
| 118 | - new InputArgument( |
|
| 119 | - self::ARGUMENT_NAME, |
|
| 120 | - $mode, |
|
| 121 | - '', |
|
| 122 | - null, |
|
| 123 | - ), |
|
| 124 | - '10', |
|
| 125 | - TypedInput::createForScalar( |
|
| 126 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10\'"'), |
|
| 127 | - true, |
|
| 128 | - true, |
|
| 129 | - '10', |
|
| 130 | - '10', |
|
| 131 | - 10, |
|
| 132 | - 10, |
|
| 133 | - 10., |
|
| 134 | - 10., |
|
| 135 | - ), |
|
| 136 | - ]; |
|
| 137 | - |
|
| 138 | - // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 139 | - |
|
| 140 | - yield 'zero integer string' => [ |
|
| 141 | - new InputArgument( |
|
| 142 | - self::ARGUMENT_NAME, |
|
| 143 | - $mode, |
|
| 144 | - '', |
|
| 145 | - null, |
|
| 146 | - ), |
|
| 147 | - '0', |
|
| 148 | - TypedInput::createForScalar( |
|
| 149 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0\'"'), |
|
| 150 | - false, |
|
| 151 | - false, |
|
| 152 | - '0', |
|
| 153 | - '0', |
|
| 154 | - 0, |
|
| 155 | - 0, |
|
| 156 | - 0., |
|
| 157 | - 0., |
|
| 158 | - ), |
|
| 159 | - ]; |
|
| 160 | - |
|
| 161 | - yield 'float string' => [ |
|
| 162 | - new InputArgument( |
|
| 163 | - self::ARGUMENT_NAME, |
|
| 164 | - $mode, |
|
| 165 | - '', |
|
| 166 | - null, |
|
| 167 | - ), |
|
| 168 | - '10.8', |
|
| 169 | - TypedInput::createForScalar( |
|
| 170 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10.8\'"'), |
|
| 171 | - true, |
|
| 172 | - true, |
|
| 173 | - '10.8', |
|
| 174 | - '10.8', |
|
| 175 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 176 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 177 | - 10.8, |
|
| 178 | - 10.8, |
|
| 179 | - ), |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 183 | - |
|
| 184 | - yield 'zero float string' => [ |
|
| 185 | - new InputArgument( |
|
| 186 | - self::ARGUMENT_NAME, |
|
| 187 | - $mode, |
|
| 188 | - '', |
|
| 189 | - null, |
|
| 190 | - ), |
|
| 191 | - '0.', |
|
| 192 | - TypedInput::createForScalar( |
|
| 193 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0.\'"'), |
|
| 194 | - true, |
|
| 195 | - true, |
|
| 196 | - '0.', |
|
| 197 | - '0.', |
|
| 198 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 199 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 200 | - 0., |
|
| 201 | - 0., |
|
| 202 | - ), |
|
| 203 | - ]; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public static function optionalArgumentProvider(): iterable |
|
| 207 | - { |
|
| 208 | - yield 'empty string' => [ |
|
| 209 | - new InputArgument( |
|
| 210 | - self::ARGUMENT_NAME, |
|
| 211 | - InputArgument::OPTIONAL, |
|
| 212 | - '', |
|
| 213 | - null, |
|
| 214 | - ), |
|
| 215 | - '', |
|
| 216 | - TypedInput::createForScalar( |
|
| 217 | - new TypeException('Cannot cast a non-array input argument into an array. Got the value "NULL"'), |
|
| 218 | - false, |
|
| 219 | - null, |
|
| 220 | - '', |
|
| 221 | - null, |
|
| 222 | - new TypeException('Expected an integer. Got "NULL"'), |
|
| 223 | - null, |
|
| 224 | - new TypeException('Expected a numeric. Got "NULL"'), |
|
| 225 | - null, |
|
| 226 | - ), |
|
| 227 | - ]; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - public static function arrayArgumentProvider(): iterable |
|
| 231 | - { |
|
| 232 | - $mode = InputArgument::IS_ARRAY; |
|
| 233 | - |
|
| 234 | - yield 'empty string' => [ |
|
| 235 | - new InputArgument( |
|
| 236 | - self::ARGUMENT_NAME, |
|
| 237 | - $mode, |
|
| 238 | - '', |
|
| 239 | - null, |
|
| 240 | - ), |
|
| 241 | - '""', |
|
| 242 | - TypedInput::createForArray( |
|
| 243 | - new TypeException( |
|
| 244 | - <<<'TXT' |
|
| 29 | + private const ARGUMENT_NAME = 'arg'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @dataProvider requiredArgumentProvider |
|
| 33 | + * @dataProvider optionalArgumentProvider |
|
| 34 | + * @dataProvider arrayArgumentProvider |
|
| 35 | + */ |
|
| 36 | + public function test_it_exposes_a_typed_api( |
|
| 37 | + InputArgument $inputArgument, |
|
| 38 | + string $argument, |
|
| 39 | + TypedInput $expected |
|
| 40 | + ): void { |
|
| 41 | + $io = $this->getIO($inputArgument, $argument); |
|
| 42 | + |
|
| 43 | + TypeAssertions::assertExpectedArgumentTypes( |
|
| 44 | + $expected, |
|
| 45 | + $io, |
|
| 46 | + self::ARGUMENT_NAME, |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public static function requiredArgumentProvider(): iterable |
|
| 51 | + { |
|
| 52 | + $mode = InputArgument::REQUIRED; |
|
| 53 | + |
|
| 54 | + yield 'empty string' => [ |
|
| 55 | + new InputArgument( |
|
| 56 | + self::ARGUMENT_NAME, |
|
| 57 | + $mode, |
|
| 58 | + '', |
|
| 59 | + null, |
|
| 60 | + ), |
|
| 61 | + '""', |
|
| 62 | + TypedInput::createForScalar( |
|
| 63 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'\'"'), |
|
| 64 | + false, |
|
| 65 | + false, |
|
| 66 | + '', |
|
| 67 | + '', |
|
| 68 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 69 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 70 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 71 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 72 | + ), |
|
| 73 | + ]; |
|
| 74 | + |
|
| 75 | + yield 'nominal string' => [ |
|
| 76 | + new InputArgument( |
|
| 77 | + self::ARGUMENT_NAME, |
|
| 78 | + $mode, |
|
| 79 | + '', |
|
| 80 | + null, |
|
| 81 | + ), |
|
| 82 | + 'foo', |
|
| 83 | + TypedInput::createForScalar( |
|
| 84 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'foo\'"'), |
|
| 85 | + true, |
|
| 86 | + true, |
|
| 87 | + 'foo', |
|
| 88 | + 'foo', |
|
| 89 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 90 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 91 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 92 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 93 | + ), |
|
| 94 | + ]; |
|
| 95 | + |
|
| 96 | + yield 'null string' => [ |
|
| 97 | + new InputArgument( |
|
| 98 | + self::ARGUMENT_NAME, |
|
| 99 | + $mode, |
|
| 100 | + '', |
|
| 101 | + null, |
|
| 102 | + ), |
|
| 103 | + 'null', |
|
| 104 | + TypedInput::createForScalar( |
|
| 105 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'null\'"'), |
|
| 106 | + true, |
|
| 107 | + true, |
|
| 108 | + 'null', |
|
| 109 | + 'null', |
|
| 110 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 111 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 112 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 113 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 114 | + ), |
|
| 115 | + ]; |
|
| 116 | + |
|
| 117 | + yield 'integer string' => [ |
|
| 118 | + new InputArgument( |
|
| 119 | + self::ARGUMENT_NAME, |
|
| 120 | + $mode, |
|
| 121 | + '', |
|
| 122 | + null, |
|
| 123 | + ), |
|
| 124 | + '10', |
|
| 125 | + TypedInput::createForScalar( |
|
| 126 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10\'"'), |
|
| 127 | + true, |
|
| 128 | + true, |
|
| 129 | + '10', |
|
| 130 | + '10', |
|
| 131 | + 10, |
|
| 132 | + 10, |
|
| 133 | + 10., |
|
| 134 | + 10., |
|
| 135 | + ), |
|
| 136 | + ]; |
|
| 137 | + |
|
| 138 | + // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 139 | + |
|
| 140 | + yield 'zero integer string' => [ |
|
| 141 | + new InputArgument( |
|
| 142 | + self::ARGUMENT_NAME, |
|
| 143 | + $mode, |
|
| 144 | + '', |
|
| 145 | + null, |
|
| 146 | + ), |
|
| 147 | + '0', |
|
| 148 | + TypedInput::createForScalar( |
|
| 149 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0\'"'), |
|
| 150 | + false, |
|
| 151 | + false, |
|
| 152 | + '0', |
|
| 153 | + '0', |
|
| 154 | + 0, |
|
| 155 | + 0, |
|
| 156 | + 0., |
|
| 157 | + 0., |
|
| 158 | + ), |
|
| 159 | + ]; |
|
| 160 | + |
|
| 161 | + yield 'float string' => [ |
|
| 162 | + new InputArgument( |
|
| 163 | + self::ARGUMENT_NAME, |
|
| 164 | + $mode, |
|
| 165 | + '', |
|
| 166 | + null, |
|
| 167 | + ), |
|
| 168 | + '10.8', |
|
| 169 | + TypedInput::createForScalar( |
|
| 170 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'10.8\'"'), |
|
| 171 | + true, |
|
| 172 | + true, |
|
| 173 | + '10.8', |
|
| 174 | + '10.8', |
|
| 175 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 176 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 177 | + 10.8, |
|
| 178 | + 10.8, |
|
| 179 | + ), |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 183 | + |
|
| 184 | + yield 'zero float string' => [ |
|
| 185 | + new InputArgument( |
|
| 186 | + self::ARGUMENT_NAME, |
|
| 187 | + $mode, |
|
| 188 | + '', |
|
| 189 | + null, |
|
| 190 | + ), |
|
| 191 | + '0.', |
|
| 192 | + TypedInput::createForScalar( |
|
| 193 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "\'0.\'"'), |
|
| 194 | + true, |
|
| 195 | + true, |
|
| 196 | + '0.', |
|
| 197 | + '0.', |
|
| 198 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 199 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 200 | + 0., |
|
| 201 | + 0., |
|
| 202 | + ), |
|
| 203 | + ]; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public static function optionalArgumentProvider(): iterable |
|
| 207 | + { |
|
| 208 | + yield 'empty string' => [ |
|
| 209 | + new InputArgument( |
|
| 210 | + self::ARGUMENT_NAME, |
|
| 211 | + InputArgument::OPTIONAL, |
|
| 212 | + '', |
|
| 213 | + null, |
|
| 214 | + ), |
|
| 215 | + '', |
|
| 216 | + TypedInput::createForScalar( |
|
| 217 | + new TypeException('Cannot cast a non-array input argument into an array. Got the value "NULL"'), |
|
| 218 | + false, |
|
| 219 | + null, |
|
| 220 | + '', |
|
| 221 | + null, |
|
| 222 | + new TypeException('Expected an integer. Got "NULL"'), |
|
| 223 | + null, |
|
| 224 | + new TypeException('Expected a numeric. Got "NULL"'), |
|
| 225 | + null, |
|
| 226 | + ), |
|
| 227 | + ]; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + public static function arrayArgumentProvider(): iterable |
|
| 231 | + { |
|
| 232 | + $mode = InputArgument::IS_ARRAY; |
|
| 233 | + |
|
| 234 | + yield 'empty string' => [ |
|
| 235 | + new InputArgument( |
|
| 236 | + self::ARGUMENT_NAME, |
|
| 237 | + $mode, |
|
| 238 | + '', |
|
| 239 | + null, |
|
| 240 | + ), |
|
| 241 | + '""', |
|
| 242 | + TypedInput::createForArray( |
|
| 243 | + new TypeException( |
|
| 244 | + <<<'TXT' |
|
| 245 | 245 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 246 | 246 | 0 => '', |
| 247 | 247 | )" |
| 248 | 248 | TXT, |
| 249 | - ), |
|
| 250 | - [''], |
|
| 251 | - new TypeException('Expected an integer. Got "\'\'"'), |
|
| 252 | - new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 253 | - ), |
|
| 254 | - ]; |
|
| 255 | - |
|
| 256 | - yield 'single element string' => [ |
|
| 257 | - new InputArgument( |
|
| 258 | - self::ARGUMENT_NAME, |
|
| 259 | - $mode, |
|
| 260 | - '', |
|
| 261 | - null, |
|
| 262 | - ), |
|
| 263 | - 'foo', |
|
| 264 | - TypedInput::createForArray( |
|
| 265 | - new TypeException( |
|
| 266 | - <<<'TXT' |
|
| 249 | + ), |
|
| 250 | + [''], |
|
| 251 | + new TypeException('Expected an integer. Got "\'\'"'), |
|
| 252 | + new TypeException('Expected a numeric. Got "\'\'"'), |
|
| 253 | + ), |
|
| 254 | + ]; |
|
| 255 | + |
|
| 256 | + yield 'single element string' => [ |
|
| 257 | + new InputArgument( |
|
| 258 | + self::ARGUMENT_NAME, |
|
| 259 | + $mode, |
|
| 260 | + '', |
|
| 261 | + null, |
|
| 262 | + ), |
|
| 263 | + 'foo', |
|
| 264 | + TypedInput::createForArray( |
|
| 265 | + new TypeException( |
|
| 266 | + <<<'TXT' |
|
| 267 | 267 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 268 | 268 | 0 => 'foo', |
| 269 | 269 | )" |
| 270 | 270 | TXT, |
| 271 | - ), |
|
| 272 | - ['foo'], |
|
| 273 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 274 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 275 | - ), |
|
| 276 | - ]; |
|
| 277 | - |
|
| 278 | - yield 'multiple elements string' => [ |
|
| 279 | - new InputArgument( |
|
| 280 | - self::ARGUMENT_NAME, |
|
| 281 | - $mode, |
|
| 282 | - '', |
|
| 283 | - null, |
|
| 284 | - ), |
|
| 285 | - 'foo bar baz', |
|
| 286 | - TypedInput::createForArray( |
|
| 287 | - new TypeException( |
|
| 288 | - <<<'TXT' |
|
| 271 | + ), |
|
| 272 | + ['foo'], |
|
| 273 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 274 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 275 | + ), |
|
| 276 | + ]; |
|
| 277 | + |
|
| 278 | + yield 'multiple elements string' => [ |
|
| 279 | + new InputArgument( |
|
| 280 | + self::ARGUMENT_NAME, |
|
| 281 | + $mode, |
|
| 282 | + '', |
|
| 283 | + null, |
|
| 284 | + ), |
|
| 285 | + 'foo bar baz', |
|
| 286 | + TypedInput::createForArray( |
|
| 287 | + new TypeException( |
|
| 288 | + <<<'TXT' |
|
| 289 | 289 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 290 | 290 | 0 => 'foo', |
| 291 | 291 | 1 => 'bar', |
| 292 | 292 | 2 => 'baz', |
| 293 | 293 | )" |
| 294 | 294 | TXT, |
| 295 | - ), |
|
| 296 | - ['foo', 'bar', 'baz'], |
|
| 297 | - new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 298 | - new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 299 | - ), |
|
| 300 | - ]; |
|
| 301 | - |
|
| 302 | - yield 'null string' => [ |
|
| 303 | - new InputArgument( |
|
| 304 | - self::ARGUMENT_NAME, |
|
| 305 | - $mode, |
|
| 306 | - '', |
|
| 307 | - null, |
|
| 308 | - ), |
|
| 309 | - 'null', |
|
| 310 | - TypedInput::createForArray( |
|
| 311 | - new TypeException( |
|
| 312 | - <<<'TXT' |
|
| 295 | + ), |
|
| 296 | + ['foo', 'bar', 'baz'], |
|
| 297 | + new TypeException('Expected an integer. Got "\'foo\'"'), |
|
| 298 | + new TypeException('Expected a numeric. Got "\'foo\'"'), |
|
| 299 | + ), |
|
| 300 | + ]; |
|
| 301 | + |
|
| 302 | + yield 'null string' => [ |
|
| 303 | + new InputArgument( |
|
| 304 | + self::ARGUMENT_NAME, |
|
| 305 | + $mode, |
|
| 306 | + '', |
|
| 307 | + null, |
|
| 308 | + ), |
|
| 309 | + 'null', |
|
| 310 | + TypedInput::createForArray( |
|
| 311 | + new TypeException( |
|
| 312 | + <<<'TXT' |
|
| 313 | 313 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 314 | 314 | 0 => 'null', |
| 315 | 315 | )" |
| 316 | 316 | TXT, |
| 317 | - ), |
|
| 318 | - ['null'], |
|
| 319 | - new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 320 | - new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 321 | - ), |
|
| 322 | - ]; |
|
| 323 | - |
|
| 324 | - yield 'integer string' => [ |
|
| 325 | - new InputArgument( |
|
| 326 | - self::ARGUMENT_NAME, |
|
| 327 | - $mode, |
|
| 328 | - '', |
|
| 329 | - null, |
|
| 330 | - ), |
|
| 331 | - '10', |
|
| 332 | - TypedInput::createForArray( |
|
| 333 | - new TypeException( |
|
| 334 | - <<<'TXT' |
|
| 317 | + ), |
|
| 318 | + ['null'], |
|
| 319 | + new TypeException('Expected an integer. Got "\'null\'"'), |
|
| 320 | + new TypeException('Expected a numeric. Got "\'null\'"'), |
|
| 321 | + ), |
|
| 322 | + ]; |
|
| 323 | + |
|
| 324 | + yield 'integer string' => [ |
|
| 325 | + new InputArgument( |
|
| 326 | + self::ARGUMENT_NAME, |
|
| 327 | + $mode, |
|
| 328 | + '', |
|
| 329 | + null, |
|
| 330 | + ), |
|
| 331 | + '10', |
|
| 332 | + TypedInput::createForArray( |
|
| 333 | + new TypeException( |
|
| 334 | + <<<'TXT' |
|
| 335 | 335 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 336 | 336 | 0 => '10', |
| 337 | 337 | )" |
| 338 | 338 | TXT, |
| 339 | - ), |
|
| 340 | - ['10'], |
|
| 341 | - [10], |
|
| 342 | - [10.], |
|
| 343 | - ), |
|
| 344 | - ]; |
|
| 345 | - |
|
| 346 | - // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 347 | - |
|
| 348 | - yield 'zero integer string' => [ |
|
| 349 | - new InputArgument( |
|
| 350 | - self::ARGUMENT_NAME, |
|
| 351 | - $mode, |
|
| 352 | - '', |
|
| 353 | - null, |
|
| 354 | - ), |
|
| 355 | - '0', |
|
| 356 | - TypedInput::createForArray( |
|
| 357 | - new TypeException( |
|
| 358 | - <<<'TXT' |
|
| 339 | + ), |
|
| 340 | + ['10'], |
|
| 341 | + [10], |
|
| 342 | + [10.], |
|
| 343 | + ), |
|
| 344 | + ]; |
|
| 345 | + |
|
| 346 | + // negative integer string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 347 | + |
|
| 348 | + yield 'zero integer string' => [ |
|
| 349 | + new InputArgument( |
|
| 350 | + self::ARGUMENT_NAME, |
|
| 351 | + $mode, |
|
| 352 | + '', |
|
| 353 | + null, |
|
| 354 | + ), |
|
| 355 | + '0', |
|
| 356 | + TypedInput::createForArray( |
|
| 357 | + new TypeException( |
|
| 358 | + <<<'TXT' |
|
| 359 | 359 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 360 | 360 | 0 => '0', |
| 361 | 361 | )" |
| 362 | 362 | TXT, |
| 363 | - ), |
|
| 364 | - ['0'], |
|
| 365 | - [0], |
|
| 366 | - [0.], |
|
| 367 | - ), |
|
| 368 | - ]; |
|
| 369 | - |
|
| 370 | - yield 'float string' => [ |
|
| 371 | - new InputArgument( |
|
| 372 | - self::ARGUMENT_NAME, |
|
| 373 | - $mode, |
|
| 374 | - '', |
|
| 375 | - null, |
|
| 376 | - ), |
|
| 377 | - '10.8', |
|
| 378 | - TypedInput::createForArray( |
|
| 379 | - new TypeException( |
|
| 380 | - <<<'TXT' |
|
| 363 | + ), |
|
| 364 | + ['0'], |
|
| 365 | + [0], |
|
| 366 | + [0.], |
|
| 367 | + ), |
|
| 368 | + ]; |
|
| 369 | + |
|
| 370 | + yield 'float string' => [ |
|
| 371 | + new InputArgument( |
|
| 372 | + self::ARGUMENT_NAME, |
|
| 373 | + $mode, |
|
| 374 | + '', |
|
| 375 | + null, |
|
| 376 | + ), |
|
| 377 | + '10.8', |
|
| 378 | + TypedInput::createForArray( |
|
| 379 | + new TypeException( |
|
| 380 | + <<<'TXT' |
|
| 381 | 381 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 382 | 382 | 0 => '10.8', |
| 383 | 383 | )" |
| 384 | 384 | TXT, |
| 385 | - ), |
|
| 386 | - ['10.8'], |
|
| 387 | - new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 388 | - [10.8], |
|
| 389 | - ), |
|
| 390 | - ]; |
|
| 391 | - |
|
| 392 | - // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 393 | - |
|
| 394 | - yield 'zero float string' => [ |
|
| 395 | - new InputArgument( |
|
| 396 | - self::ARGUMENT_NAME, |
|
| 397 | - $mode, |
|
| 398 | - '', |
|
| 399 | - null, |
|
| 400 | - ), |
|
| 401 | - '0.', |
|
| 402 | - TypedInput::createForArray( |
|
| 403 | - new TypeException( |
|
| 404 | - <<<'TXT' |
|
| 385 | + ), |
|
| 386 | + ['10.8'], |
|
| 387 | + new TypeException('Expected an integer. Got "\'10.8\'"'), |
|
| 388 | + [10.8], |
|
| 389 | + ), |
|
| 390 | + ]; |
|
| 391 | + |
|
| 392 | + // negative float string case: skipped see https://github.com/symfony/symfony/issues/27333 |
|
| 393 | + |
|
| 394 | + yield 'zero float string' => [ |
|
| 395 | + new InputArgument( |
|
| 396 | + self::ARGUMENT_NAME, |
|
| 397 | + $mode, |
|
| 398 | + '', |
|
| 399 | + null, |
|
| 400 | + ), |
|
| 401 | + '0.', |
|
| 402 | + TypedInput::createForArray( |
|
| 403 | + new TypeException( |
|
| 404 | + <<<'TXT' |
|
| 405 | 405 | Cannot cast an array input argument as a scalar. Got the argument value: "array ( |
| 406 | 406 | 0 => '0.', |
| 407 | 407 | )" |
| 408 | 408 | TXT, |
| 409 | - ), |
|
| 410 | - ['0.'], |
|
| 411 | - new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 412 | - [0.], |
|
| 413 | - ), |
|
| 414 | - ]; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - private function getIO( |
|
| 418 | - InputArgument $inputArgument, |
|
| 419 | - string $argument |
|
| 420 | - ): IO { |
|
| 421 | - $application = new Application(); |
|
| 422 | - $application->add( |
|
| 423 | - new DynamicCommandWithArguments($inputArgument), |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - $input = new StringInput('app:input:args '.$argument); |
|
| 427 | - $input->setInteractive(false); |
|
| 428 | - |
|
| 429 | - $application->doRun( |
|
| 430 | - $input, |
|
| 431 | - new NullOutput(), |
|
| 432 | - ); |
|
| 433 | - |
|
| 434 | - $command = $application->find('app:input:args'); |
|
| 435 | - self::assertInstanceOf(DynamicCommandWithArguments::class, $command); |
|
| 436 | - |
|
| 437 | - return new IO( |
|
| 438 | - $command->input, |
|
| 439 | - new NullOutput(), |
|
| 440 | - ); |
|
| 441 | - } |
|
| 409 | + ), |
|
| 410 | + ['0.'], |
|
| 411 | + new TypeException('Expected an integer. Got "\'0.\'"'), |
|
| 412 | + [0.], |
|
| 413 | + ), |
|
| 414 | + ]; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + private function getIO( |
|
| 418 | + InputArgument $inputArgument, |
|
| 419 | + string $argument |
|
| 420 | + ): IO { |
|
| 421 | + $application = new Application(); |
|
| 422 | + $application->add( |
|
| 423 | + new DynamicCommandWithArguments($inputArgument), |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + $input = new StringInput('app:input:args '.$argument); |
|
| 427 | + $input->setInteractive(false); |
|
| 428 | + |
|
| 429 | + $application->doRun( |
|
| 430 | + $input, |
|
| 431 | + new NullOutput(), |
|
| 432 | + ); |
|
| 433 | + |
|
| 434 | + $command = $application->find('app:input:args'); |
|
| 435 | + self::assertInstanceOf(DynamicCommandWithArguments::class, $command); |
|
| 436 | + |
|
| 437 | + return new IO( |
|
| 438 | + $command->input, |
|
| 439 | + new NullOutput(), |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | 442 | } |
@@ -24,8 +24,7 @@ |
||
| 24 | 24 | * @covers \Fidry\Console\Command\ConsoleAssert |
| 25 | 25 | * @covers \Fidry\Console\IO |
| 26 | 26 | */ |
| 27 | -final class IOArgumentTest extends TestCase |
|
| 28 | -{ |
|
| 27 | +final class IOArgumentTest extends TestCase { |
|
| 29 | 28 | private const ARGUMENT_NAME = 'arg'; |
| 30 | 29 | |
| 31 | 30 | /** |