@@ -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 | /** |
@@ -23,43 +23,43 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | final class CommandLazinessSupportTest extends KernelTestCase |
| 25 | 25 | { |
| 26 | - private StatefulService $service; |
|
| 26 | + private StatefulService $service; |
|
| 27 | 27 | |
| 28 | - protected function setUp(): void |
|
| 29 | - { |
|
| 30 | - self::bootKernel(); |
|
| 28 | + protected function setUp(): void |
|
| 29 | + { |
|
| 30 | + self::bootKernel(); |
|
| 31 | 31 | |
| 32 | - $this->service = self::$kernel->getContainer()->get(StatefulService::class); |
|
| 33 | - } |
|
| 32 | + $this->service = self::$kernel->getContainer()->get(StatefulService::class); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function test_it_is_instantiated_lazily(): void |
|
| 36 | - { |
|
| 37 | - // Sanity check |
|
| 38 | - self::assertFalse($this->service->called); |
|
| 35 | + public function test_it_is_instantiated_lazily(): void |
|
| 36 | + { |
|
| 37 | + // Sanity check |
|
| 38 | + self::assertFalse($this->service->called); |
|
| 39 | 39 | |
| 40 | - // Finding another command – if command is not lazy it will be loaded |
|
| 41 | - (new Application(self::$kernel))->find('app:foo'); |
|
| 40 | + // Finding another command – if command is not lazy it will be loaded |
|
| 41 | + (new Application(self::$kernel))->find('app:foo'); |
|
| 42 | 42 | |
| 43 | - /** @psalm-suppress RedundantConditionGivenDocblockType */ |
|
| 44 | - self::assertFalse($this->service->called); |
|
| 43 | + /** @psalm-suppress RedundantConditionGivenDocblockType */ |
|
| 44 | + self::assertFalse($this->service->called); |
|
| 45 | 45 | |
| 46 | - (new Application(self::$kernel))->find('app:lazy'); |
|
| 46 | + (new Application(self::$kernel))->find('app:lazy'); |
|
| 47 | 47 | |
| 48 | - /** @psalm-suppress DocblockTypeContradiction */ |
|
| 49 | - self::assertTrue($this->service->called); |
|
| 50 | - } |
|
| 48 | + /** @psalm-suppress DocblockTypeContradiction */ |
|
| 49 | + self::assertTrue($this->service->called); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function test_it_can_be_executed(): void |
|
| 53 | - { |
|
| 54 | - // Sanity check |
|
| 55 | - self::assertFalse($this->service->called); |
|
| 52 | + public function test_it_can_be_executed(): void |
|
| 53 | + { |
|
| 54 | + // Sanity check |
|
| 55 | + self::assertFalse($this->service->called); |
|
| 56 | 56 | |
| 57 | - $command = (new Application(self::$kernel))->find('app:lazy'); |
|
| 58 | - $tester = new CommandTester($command); |
|
| 57 | + $command = (new Application(self::$kernel))->find('app:lazy'); |
|
| 58 | + $tester = new CommandTester($command); |
|
| 59 | 59 | |
| 60 | - $tester->execute([], ['interactive' => false]); |
|
| 60 | + $tester->execute([], ['interactive' => false]); |
|
| 61 | 61 | |
| 62 | - /** @psalm-suppress DocblockTypeContradiction */ |
|
| 63 | - self::assertTrue($this->service->called); |
|
| 64 | - } |
|
| 62 | + /** @psalm-suppress DocblockTypeContradiction */ |
|
| 63 | + self::assertTrue($this->service->called); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | /** |
| 22 | 22 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 23 | 23 | */ |
| 24 | -final class CommandLazinessSupportTest extends KernelTestCase |
|
| 25 | -{ |
|
| 24 | +final class CommandLazinessSupportTest extends KernelTestCase { |
|
| 26 | 25 | private StatefulService $service; |
| 27 | 26 | |
| 28 | 27 | protected function setUp(): void |
@@ -24,28 +24,28 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | final class CommandServiceInjectionSupportTest extends KernelTestCase |
| 26 | 26 | { |
| 27 | - private Command $command; |
|
| 28 | - private CommandTester $tester; |
|
| 29 | - private StatefulService $service; |
|
| 27 | + private Command $command; |
|
| 28 | + private CommandTester $tester; |
|
| 29 | + private StatefulService $service; |
|
| 30 | 30 | |
| 31 | - protected function setUp(): void |
|
| 32 | - { |
|
| 33 | - $kernel = self::bootKernel(); |
|
| 31 | + protected function setUp(): void |
|
| 32 | + { |
|
| 33 | + $kernel = self::bootKernel(); |
|
| 34 | 34 | |
| 35 | - $this->command = (new Application($kernel))->find('app:with-service'); |
|
| 36 | - $this->tester = new CommandTester($this->command); |
|
| 35 | + $this->command = (new Application($kernel))->find('app:with-service'); |
|
| 36 | + $this->tester = new CommandTester($this->command); |
|
| 37 | 37 | |
| 38 | - $this->service = $kernel->getContainer()->get(StatefulService::class); |
|
| 39 | - } |
|
| 38 | + $this->service = $kernel->getContainer()->get(StatefulService::class); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function test_it_can_be_executed(): void |
|
| 42 | - { |
|
| 43 | - // Sanity check |
|
| 44 | - self::assertFalse($this->service->called); |
|
| 41 | + public function test_it_can_be_executed(): void |
|
| 42 | + { |
|
| 43 | + // Sanity check |
|
| 44 | + self::assertFalse($this->service->called); |
|
| 45 | 45 | |
| 46 | - $this->tester->execute([], ['interactive' => false]); |
|
| 46 | + $this->tester->execute([], ['interactive' => false]); |
|
| 47 | 47 | |
| 48 | - /** @psalm-suppress DocblockTypeContradiction */ |
|
| 49 | - self::assertTrue($this->service->called); |
|
| 50 | - } |
|
| 48 | + /** @psalm-suppress DocblockTypeContradiction */ |
|
| 49 | + self::assertTrue($this->service->called); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | /** |
| 23 | 23 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 24 | 24 | */ |
| 25 | -final class CommandServiceInjectionSupportTest extends KernelTestCase |
|
| 26 | -{ |
|
| 25 | +final class CommandServiceInjectionSupportTest extends KernelTestCase { |
|
| 27 | 26 | private Command $command; |
| 28 | 27 | private CommandTester $tester; |
| 29 | 28 | private StatefulService $service; |
@@ -25,52 +25,52 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | final class CommandMetaDescriptionSupportTest extends KernelTestCase |
| 27 | 27 | { |
| 28 | - private Command $command; |
|
| 29 | - private CommandTester $tester; |
|
| 28 | + private Command $command; |
|
| 29 | + private CommandTester $tester; |
|
| 30 | 30 | |
| 31 | - protected function setUp(): void |
|
| 32 | - { |
|
| 33 | - $kernel = self::bootKernel(); |
|
| 31 | + protected function setUp(): void |
|
| 32 | + { |
|
| 33 | + $kernel = self::bootKernel(); |
|
| 34 | 34 | |
| 35 | - $this->command = (new Application($kernel))->find('app:foo'); |
|
| 36 | - $this->tester = new CommandTester($this->command); |
|
| 37 | - } |
|
| 35 | + $this->command = (new Application($kernel))->find('app:foo'); |
|
| 36 | + $this->tester = new CommandTester($this->command); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function test_it_supports_the_command_meta_description(): void |
|
| 40 | - { |
|
| 41 | - self::assertMatchesRegularExpression( |
|
| 42 | - '/^Command name: "app:foo", command full name: ".+ app:foo"$/', |
|
| 43 | - $this->command->getProcessedHelp(), |
|
| 44 | - ); |
|
| 39 | + public function test_it_supports_the_command_meta_description(): void |
|
| 40 | + { |
|
| 41 | + self::assertMatchesRegularExpression( |
|
| 42 | + '/^Command name: "app:foo", command full name: ".+ app:foo"$/', |
|
| 43 | + $this->command->getProcessedHelp(), |
|
| 44 | + ); |
|
| 45 | 45 | |
| 46 | - CommandAssertions::assertSameMetaDescription( |
|
| 47 | - $this->command, |
|
| 48 | - 'app:foo', |
|
| 49 | - 'Description content', |
|
| 50 | - $this->command->getProcessedHelp(), |
|
| 51 | - 'app:foo', |
|
| 52 | - ); |
|
| 53 | - } |
|
| 46 | + CommandAssertions::assertSameMetaDescription( |
|
| 47 | + $this->command, |
|
| 48 | + 'app:foo', |
|
| 49 | + 'Description content', |
|
| 50 | + $this->command->getProcessedHelp(), |
|
| 51 | + 'app:foo', |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function test_it_can_be_executed_non_interactively(): void |
|
| 56 | - { |
|
| 57 | - $this->tester->execute([], ['interactive' => false]); |
|
| 55 | + public function test_it_can_be_executed_non_interactively(): void |
|
| 56 | + { |
|
| 57 | + $this->tester->execute([], ['interactive' => false]); |
|
| 58 | 58 | |
| 59 | - CommandAssertions::assertSameOutput( |
|
| 60 | - $this->tester, |
|
| 61 | - ExitCode::SUCCESS, |
|
| 62 | - '', |
|
| 63 | - ); |
|
| 64 | - } |
|
| 59 | + CommandAssertions::assertSameOutput( |
|
| 60 | + $this->tester, |
|
| 61 | + ExitCode::SUCCESS, |
|
| 62 | + '', |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function test_it_can_be_executed_interactively(): void |
|
| 67 | - { |
|
| 68 | - $this->tester->execute([], ['interactive' => true]); |
|
| 66 | + public function test_it_can_be_executed_interactively(): void |
|
| 67 | + { |
|
| 68 | + $this->tester->execute([], ['interactive' => true]); |
|
| 69 | 69 | |
| 70 | - CommandAssertions::assertSameOutput( |
|
| 71 | - $this->tester, |
|
| 72 | - ExitCode::SUCCESS, |
|
| 73 | - '', |
|
| 74 | - ); |
|
| 75 | - } |
|
| 70 | + CommandAssertions::assertSameOutput( |
|
| 71 | + $this->tester, |
|
| 72 | + ExitCode::SUCCESS, |
|
| 73 | + '', |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | /** |
| 24 | 24 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 25 | 25 | */ |
| 26 | -final class CommandMetaDescriptionSupportTest extends KernelTestCase |
|
| 27 | -{ |
|
| 26 | +final class CommandMetaDescriptionSupportTest extends KernelTestCase { |
|
| 28 | 27 | private Command $command; |
| 29 | 28 | private CommandTester $tester; |
| 30 | 29 | |
@@ -25,63 +25,63 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | final class CommandArgumentsAndOptionsSupportTest extends KernelTestCase |
| 27 | 27 | { |
| 28 | - private Command $command; |
|
| 29 | - private CommandTester $tester; |
|
| 28 | + private Command $command; |
|
| 29 | + private CommandTester $tester; |
|
| 30 | 30 | |
| 31 | - protected function setUp(): void |
|
| 32 | - { |
|
| 33 | - $kernel = self::bootKernel(); |
|
| 31 | + protected function setUp(): void |
|
| 32 | + { |
|
| 33 | + $kernel = self::bootKernel(); |
|
| 34 | 34 | |
| 35 | - $this->command = (new Application($kernel))->find('app:print-arg-opt'); |
|
| 36 | - $this->tester = new CommandTester($this->command); |
|
| 37 | - } |
|
| 35 | + $this->command = (new Application($kernel))->find('app:print-arg-opt'); |
|
| 36 | + $this->tester = new CommandTester($this->command); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function test_it_supports_the_command_meta_description(): void |
|
| 40 | - { |
|
| 41 | - CommandAssertions::assertSameMetaDescription( |
|
| 42 | - $this->command, |
|
| 43 | - 'app:print-arg-opt', |
|
| 44 | - '', |
|
| 45 | - '', |
|
| 46 | - 'app:print-arg-opt [-o|--opt] [--] <arg>', |
|
| 47 | - ); |
|
| 48 | - self::assertSame('app:print-arg-opt', $this->command->getName()); |
|
| 49 | - } |
|
| 39 | + public function test_it_supports_the_command_meta_description(): void |
|
| 40 | + { |
|
| 41 | + CommandAssertions::assertSameMetaDescription( |
|
| 42 | + $this->command, |
|
| 43 | + 'app:print-arg-opt', |
|
| 44 | + '', |
|
| 45 | + '', |
|
| 46 | + 'app:print-arg-opt [-o|--opt] [--] <arg>', |
|
| 47 | + ); |
|
| 48 | + self::assertSame('app:print-arg-opt', $this->command->getName()); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function test_it_can_be_executed_without_an_option(): void |
|
| 52 | - { |
|
| 53 | - $this->tester->execute( |
|
| 54 | - ['arg' => 'Hello world!'], |
|
| 55 | - ['interactive' => false], |
|
| 56 | - ); |
|
| 51 | + public function test_it_can_be_executed_without_an_option(): void |
|
| 52 | + { |
|
| 53 | + $this->tester->execute( |
|
| 54 | + ['arg' => 'Hello world!'], |
|
| 55 | + ['interactive' => false], |
|
| 56 | + ); |
|
| 57 | 57 | |
| 58 | - CommandAssertions::assertSameOutput( |
|
| 59 | - $this->tester, |
|
| 60 | - ExitCode::SUCCESS, |
|
| 61 | - <<<'TEXT' |
|
| 58 | + CommandAssertions::assertSameOutput( |
|
| 59 | + $this->tester, |
|
| 60 | + ExitCode::SUCCESS, |
|
| 61 | + <<<'TEXT' |
|
| 62 | 62 | arg: Hello world!; opt: false |
| 63 | 63 | |
| 64 | 64 | TEXT, |
| 65 | - ); |
|
| 66 | - } |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function test_it_can_be_executed_with_an_option(): void |
|
| 69 | - { |
|
| 70 | - $this->tester->execute( |
|
| 71 | - [ |
|
| 72 | - 'arg' => 'Hello world!', |
|
| 73 | - '--opt' => null, |
|
| 74 | - ], |
|
| 75 | - ['interactive' => false], |
|
| 76 | - ); |
|
| 68 | + public function test_it_can_be_executed_with_an_option(): void |
|
| 69 | + { |
|
| 70 | + $this->tester->execute( |
|
| 71 | + [ |
|
| 72 | + 'arg' => 'Hello world!', |
|
| 73 | + '--opt' => null, |
|
| 74 | + ], |
|
| 75 | + ['interactive' => false], |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - CommandAssertions::assertSameOutput( |
|
| 79 | - $this->tester, |
|
| 80 | - ExitCode::SUCCESS, |
|
| 81 | - <<<'TEXT' |
|
| 78 | + CommandAssertions::assertSameOutput( |
|
| 79 | + $this->tester, |
|
| 80 | + ExitCode::SUCCESS, |
|
| 81 | + <<<'TEXT' |
|
| 82 | 82 | arg: Hello world!; opt: true |
| 83 | 83 | |
| 84 | 84 | TEXT, |
| 85 | - ); |
|
| 86 | - } |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | /** |
| 24 | 24 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 25 | 25 | */ |
| 26 | -final class CommandArgumentsAndOptionsSupportTest extends KernelTestCase |
|
| 27 | -{ |
|
| 26 | +final class CommandArgumentsAndOptionsSupportTest extends KernelTestCase { |
|
| 28 | 27 | private Command $command; |
| 29 | 28 | private CommandTester $tester; |
| 30 | 29 | |
@@ -25,28 +25,28 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | final class CommandAwarenessSupportTest extends KernelTestCase |
| 27 | 27 | { |
| 28 | - private Command $command; |
|
| 29 | - private CommandTester $tester; |
|
| 30 | - private StatefulService $service; |
|
| 28 | + private Command $command; |
|
| 29 | + private CommandTester $tester; |
|
| 30 | + private StatefulService $service; |
|
| 31 | 31 | |
| 32 | - protected function setUp(): void |
|
| 33 | - { |
|
| 34 | - $kernel = self::bootKernel(); |
|
| 32 | + protected function setUp(): void |
|
| 33 | + { |
|
| 34 | + $kernel = self::bootKernel(); |
|
| 35 | 35 | |
| 36 | - $this->command = (new Application($kernel))->find('app:cmd-aware'); |
|
| 37 | - $this->tester = new CommandTester($this->command); |
|
| 36 | + $this->command = (new Application($kernel))->find('app:cmd-aware'); |
|
| 37 | + $this->tester = new CommandTester($this->command); |
|
| 38 | 38 | |
| 39 | - $this->service = $kernel->getContainer()->get(StatefulService::class); |
|
| 40 | - } |
|
| 39 | + $this->service = $kernel->getContainer()->get(StatefulService::class); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function test_it_can_be_executed(): void |
|
| 43 | - { |
|
| 44 | - // Sanity check |
|
| 45 | - self::assertFalse($this->service->called); |
|
| 42 | + public function test_it_can_be_executed(): void |
|
| 43 | + { |
|
| 44 | + // Sanity check |
|
| 45 | + self::assertFalse($this->service->called); |
|
| 46 | 46 | |
| 47 | - $this->tester->execute([], ['interactive' => false]); |
|
| 47 | + $this->tester->execute([], ['interactive' => false]); |
|
| 48 | 48 | |
| 49 | - /** @psalm-suppress DocblockTypeContradiction */ |
|
| 50 | - self::assertTrue($this->service->called); |
|
| 51 | - } |
|
| 49 | + /** @psalm-suppress DocblockTypeContradiction */ |
|
| 50 | + self::assertTrue($this->service->called); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * @covers \Fidry\Console\Command\CommandAwareness |
| 24 | 24 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 25 | 25 | */ |
| 26 | -final class CommandAwarenessSupportTest extends KernelTestCase |
|
| 27 | -{ |
|
| 26 | +final class CommandAwarenessSupportTest extends KernelTestCase { |
|
| 28 | 27 | private Command $command; |
| 29 | 28 | private CommandTester $tester; |
| 30 | 29 | private StatefulService $service; |
@@ -22,12 +22,12 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | final class CommandHelperInjectionSupportTest extends KernelTestCase |
| 24 | 24 | { |
| 25 | - public function test_it_can_be_instantiated(): void |
|
| 26 | - { |
|
| 27 | - $kernel = self::bootKernel(); |
|
| 25 | + public function test_it_can_be_instantiated(): void |
|
| 26 | + { |
|
| 27 | + $kernel = self::bootKernel(); |
|
| 28 | 28 | |
| 29 | - $command = (new Application($kernel))->find('app:helpers'); |
|
| 29 | + $command = (new Application($kernel))->find('app:helpers'); |
|
| 30 | 30 | |
| 31 | - self::assertInstanceOf(SymfonyCommand::class, $command); |
|
| 32 | - } |
|
| 31 | + self::assertInstanceOf(SymfonyCommand::class, $command); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | /** |
| 21 | 21 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 22 | 22 | */ |
| 23 | -final class CommandHelperInjectionSupportTest extends KernelTestCase |
|
| 24 | -{ |
|
| 23 | +final class CommandHelperInjectionSupportTest extends KernelTestCase { |
|
| 25 | 24 | public function test_it_can_be_instantiated(): void |
| 26 | 25 | { |
| 27 | 26 | $kernel = self::bootKernel(); |
@@ -26,41 +26,41 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | final class CommandFullLifeCycleSupportTest extends KernelTestCase |
| 28 | 28 | { |
| 29 | - private Command $command; |
|
| 30 | - private CommandTester $tester; |
|
| 29 | + private Command $command; |
|
| 30 | + private CommandTester $tester; |
|
| 31 | 31 | |
| 32 | - protected function setUp(): void |
|
| 33 | - { |
|
| 34 | - $kernel = self::bootKernel(); |
|
| 32 | + protected function setUp(): void |
|
| 33 | + { |
|
| 34 | + $kernel = self::bootKernel(); |
|
| 35 | 35 | |
| 36 | - $this->command = (new Application($kernel))->find('app:full-life-cycle'); |
|
| 37 | - $this->tester = new CommandTester($this->command); |
|
| 38 | - } |
|
| 36 | + $this->command = (new Application($kernel))->find('app:full-life-cycle'); |
|
| 37 | + $this->tester = new CommandTester($this->command); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function test_it_can_be_executed(): void |
|
| 41 | - { |
|
| 42 | - $this->tester->setInputs(['username' => 'Jean']); |
|
| 40 | + public function test_it_can_be_executed(): void |
|
| 41 | + { |
|
| 42 | + $this->tester->setInputs(['username' => 'Jean']); |
|
| 43 | 43 | |
| 44 | - $this->tester->execute([], ['interactive' => true]); |
|
| 44 | + $this->tester->execute([], ['interactive' => true]); |
|
| 45 | 45 | |
| 46 | - CommandAssertions::assertSameOutput( |
|
| 47 | - $this->tester, |
|
| 48 | - ExitCode::SUCCESS, |
|
| 49 | - <<<'TEXT' |
|
| 46 | + CommandAssertions::assertSameOutput( |
|
| 47 | + $this->tester, |
|
| 48 | + ExitCode::SUCCESS, |
|
| 49 | + <<<'TEXT' |
|
| 50 | 50 | Please choose a username: |
| 51 | 51 | Jean |
| 52 | 52 | |
| 53 | 53 | TEXT, |
| 54 | - ); |
|
| 55 | - } |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function test_it_ignores_interact_if_input_is_not_interactive(): void |
|
| 58 | - { |
|
| 59 | - $this->tester->setInputs(['username' => 'Jean']); |
|
| 57 | + public function test_it_ignores_interact_if_input_is_not_interactive(): void |
|
| 58 | + { |
|
| 59 | + $this->tester->setInputs(['username' => 'Jean']); |
|
| 60 | 60 | |
| 61 | - $this->expectException(RuntimeException::class); |
|
| 62 | - $this->expectErrorMessage('Not enough arguments (missing: "username")'); |
|
| 61 | + $this->expectException(RuntimeException::class); |
|
| 62 | + $this->expectErrorMessage('Not enough arguments (missing: "username")'); |
|
| 63 | 63 | |
| 64 | - $this->tester->execute([], ['interactive' => false]); |
|
| 65 | - } |
|
| 64 | + $this->tester->execute([], ['interactive' => false]); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -24,8 +24,7 @@ |
||
| 24 | 24 | /** |
| 25 | 25 | * @covers \Fidry\Console\Command\SymfonyCommand |
| 26 | 26 | */ |
| 27 | -final class CommandFullLifeCycleSupportTest extends KernelTestCase |
|
| 28 | -{ |
|
| 27 | +final class CommandFullLifeCycleSupportTest extends KernelTestCase { |
|
| 29 | 28 | private Command $command; |
| 30 | 29 | private CommandTester $tester; |
| 31 | 30 | |
@@ -23,89 +23,89 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | final class ConfigurationTest extends TestCase |
| 25 | 25 | { |
| 26 | - public function test_it_can_be_instantiated_with_minimum_params(): void |
|
| 27 | - { |
|
| 28 | - $configuration = new Configuration( |
|
| 29 | - $name = 'app:foo', |
|
| 30 | - $description = 'description', |
|
| 31 | - $help = 'help', |
|
| 32 | - ); |
|
| 26 | + public function test_it_can_be_instantiated_with_minimum_params(): void |
|
| 27 | + { |
|
| 28 | + $configuration = new Configuration( |
|
| 29 | + $name = 'app:foo', |
|
| 30 | + $description = 'description', |
|
| 31 | + $help = 'help', |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - self::assertStateIs( |
|
| 35 | - $configuration, |
|
| 36 | - $name, |
|
| 37 | - $description, |
|
| 38 | - $help, |
|
| 39 | - [], |
|
| 40 | - [], |
|
| 41 | - ); |
|
| 42 | - } |
|
| 34 | + self::assertStateIs( |
|
| 35 | + $configuration, |
|
| 36 | + $name, |
|
| 37 | + $description, |
|
| 38 | + $help, |
|
| 39 | + [], |
|
| 40 | + [], |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function test_it_can_be_instantiated_without_arguments_or_options(): void |
|
| 45 | - { |
|
| 46 | - $configuration = new Configuration( |
|
| 47 | - $name = 'app:foo', |
|
| 48 | - $description = 'description', |
|
| 49 | - $help = 'help', |
|
| 50 | - $arguments = [], |
|
| 51 | - $options = [], |
|
| 52 | - ); |
|
| 44 | + public function test_it_can_be_instantiated_without_arguments_or_options(): void |
|
| 45 | + { |
|
| 46 | + $configuration = new Configuration( |
|
| 47 | + $name = 'app:foo', |
|
| 48 | + $description = 'description', |
|
| 49 | + $help = 'help', |
|
| 50 | + $arguments = [], |
|
| 51 | + $options = [], |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - self::assertStateIs( |
|
| 55 | - $configuration, |
|
| 56 | - $name, |
|
| 57 | - $description, |
|
| 58 | - $help, |
|
| 59 | - $arguments, |
|
| 60 | - $options, |
|
| 61 | - ); |
|
| 62 | - } |
|
| 54 | + self::assertStateIs( |
|
| 55 | + $configuration, |
|
| 56 | + $name, |
|
| 57 | + $description, |
|
| 58 | + $help, |
|
| 59 | + $arguments, |
|
| 60 | + $options, |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function test_it_can_be_instantiated_with_arguments_or_options(): void |
|
| 65 | - { |
|
| 66 | - $configuration = new Configuration( |
|
| 67 | - $name = 'app:foo', |
|
| 68 | - $description = 'description', |
|
| 69 | - $help = 'help', |
|
| 70 | - $arguments = [ |
|
| 71 | - new InputArgument( |
|
| 72 | - 'arg', |
|
| 73 | - InputArgument::REQUIRED, |
|
| 74 | - 'arg description', |
|
| 75 | - ), |
|
| 76 | - ], |
|
| 77 | - $options = [ |
|
| 78 | - new InputOption( |
|
| 79 | - 'opt', |
|
| 80 | - 'o', |
|
| 81 | - InputOption::VALUE_NONE, |
|
| 82 | - 'option description', |
|
| 83 | - ), |
|
| 84 | - ], |
|
| 85 | - ); |
|
| 64 | + public function test_it_can_be_instantiated_with_arguments_or_options(): void |
|
| 65 | + { |
|
| 66 | + $configuration = new Configuration( |
|
| 67 | + $name = 'app:foo', |
|
| 68 | + $description = 'description', |
|
| 69 | + $help = 'help', |
|
| 70 | + $arguments = [ |
|
| 71 | + new InputArgument( |
|
| 72 | + 'arg', |
|
| 73 | + InputArgument::REQUIRED, |
|
| 74 | + 'arg description', |
|
| 75 | + ), |
|
| 76 | + ], |
|
| 77 | + $options = [ |
|
| 78 | + new InputOption( |
|
| 79 | + 'opt', |
|
| 80 | + 'o', |
|
| 81 | + InputOption::VALUE_NONE, |
|
| 82 | + 'option description', |
|
| 83 | + ), |
|
| 84 | + ], |
|
| 85 | + ); |
|
| 86 | 86 | |
| 87 | - self::assertStateIs( |
|
| 88 | - $configuration, |
|
| 89 | - $name, |
|
| 90 | - $description, |
|
| 91 | - $help, |
|
| 92 | - $arguments, |
|
| 93 | - $options, |
|
| 94 | - ); |
|
| 95 | - } |
|
| 87 | + self::assertStateIs( |
|
| 88 | + $configuration, |
|
| 89 | + $name, |
|
| 90 | + $description, |
|
| 91 | + $help, |
|
| 92 | + $arguments, |
|
| 93 | + $options, |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - private static function assertStateIs( |
|
| 98 | - Configuration $configuration, |
|
| 99 | - string $expectedName, |
|
| 100 | - string $expectedDescription, |
|
| 101 | - string $expectedHelp, |
|
| 102 | - array $expectedArguments, |
|
| 103 | - array $expectedOptions |
|
| 104 | - ): void { |
|
| 105 | - self::assertSame($expectedName, $configuration->getName()); |
|
| 106 | - self::assertSame($expectedDescription, $configuration->getDescription()); |
|
| 107 | - self::assertSame($expectedHelp, $configuration->getHelp()); |
|
| 108 | - self::assertEquals($expectedArguments, $configuration->getArguments()); |
|
| 109 | - self::assertEquals($expectedOptions, $configuration->getOptions()); |
|
| 110 | - } |
|
| 97 | + private static function assertStateIs( |
|
| 98 | + Configuration $configuration, |
|
| 99 | + string $expectedName, |
|
| 100 | + string $expectedDescription, |
|
| 101 | + string $expectedHelp, |
|
| 102 | + array $expectedArguments, |
|
| 103 | + array $expectedOptions |
|
| 104 | + ): void { |
|
| 105 | + self::assertSame($expectedName, $configuration->getName()); |
|
| 106 | + self::assertSame($expectedDescription, $configuration->getDescription()); |
|
| 107 | + self::assertSame($expectedHelp, $configuration->getHelp()); |
|
| 108 | + self::assertEquals($expectedArguments, $configuration->getArguments()); |
|
| 109 | + self::assertEquals($expectedOptions, $configuration->getOptions()); |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | /** |
| 22 | 22 | * @covers \Fidry\Console\Command\Configuration |
| 23 | 23 | */ |
| 24 | -final class ConfigurationTest extends TestCase |
|
| 25 | -{ |
|
| 24 | +final class ConfigurationTest extends TestCase { |
|
| 26 | 25 | public function test_it_can_be_instantiated_with_minimum_params(): void |
| 27 | 26 | { |
| 28 | 27 | $configuration = new Configuration( |