|
8 | 8 | use Lkrms\Cli\Catalog\CliOptionVisibility; |
9 | 9 | use Lkrms\Cli\CliOption; |
10 | 10 | use Lkrms\Cli\CliOptionBuilder; |
| 11 | +use Lkrms\Concept\Builder; |
11 | 12 | use Lkrms\Container\Container; |
12 | 13 | use Lkrms\Contract\IContainer; |
13 | 14 | use Lkrms\Tests\TestCase; |
@@ -216,22 +217,46 @@ public function testValue(): void |
216 | 217 | 'default' => false, |
217 | 218 | ], $option->getJsonSchema()); |
218 | 219 |
|
| 220 | + $constructor = (new ReflectionClass(CliOption::class))->getConstructor(); |
| 221 | + |
| 222 | + $option = $this->getValue(); |
| 223 | + foreach ($constructor->getParameters() as $param) { |
| 224 | + $name = $param->getName(); |
| 225 | + if ( |
| 226 | + $param->isPassedByReference() || |
| 227 | + $option->issetB($name) || |
| 228 | + method_exists(Builder::class, $name) |
| 229 | + ) { |
| 230 | + continue; |
| 231 | + } |
| 232 | + $value = null; |
| 233 | + if ($param->isDefaultValueAvailable()) { |
| 234 | + $value = $param->getDefaultValue(); |
| 235 | + } |
| 236 | + /** @var CliOptionBuilder */ |
| 237 | + $option = $option->$name($value); |
| 238 | + } |
| 239 | + $option = $option->load(); |
| 240 | + $this->assertSame(false, $option->IsBound, sprintf( |
| 241 | + 'Option bound to variable without %s::bindTo(). Check comparison with func_num_args() in %s::__construct() is >= %d', |
| 242 | + CliOptionBuilder::class, |
| 243 | + CliOption::class, |
| 244 | + $constructor->getNumberOfParameters(), |
| 245 | + )); |
| 246 | + |
219 | 247 | $bound = null; |
220 | 248 | $option = $this |
221 | 249 | ->getValue() |
222 | 250 | ->required(false) |
223 | 251 | ->multipleAllowed() |
224 | 252 | ->bindTo($bound) |
225 | 253 | ->load(); |
226 | | - $message = sprintf( |
| 254 | + $this->assertSame(true, $option->IsBound, sprintf( |
227 | 255 | '%s::bindTo() failed. Check comparison with func_num_args() in %s::__construct() is >= %d', |
228 | 256 | CliOptionBuilder::class, |
229 | 257 | CliOption::class, |
230 | | - (new ReflectionClass(CliOption::class)) |
231 | | - ->getConstructor() |
232 | | - ->getNumberOfParameters(), |
233 | | - ); |
234 | | - $this->assertSame(true, $option->IsBound, $message); |
| 258 | + $constructor->getNumberOfParameters(), |
| 259 | + )); |
235 | 260 | $this->assertNull($bound); |
236 | 261 | $option->applyValue([]); |
237 | 262 | $this->assertSame([], $bound); |
|
0 commit comments