|
62 | 62 | use Symfony\Component\Console\Command\HelpCommand; |
63 | 63 | use Symfony\Component\Console\Command\ListCommand; |
64 | 64 | use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; |
| 65 | +use Symfony\Component\Console\Input\ArrayInput; |
| 66 | +use Symfony\Component\Console\Input\InputOption; |
65 | 67 | use Symfony\Component\Console\Input\InputInterface; |
66 | 68 | use Symfony\Component\Console\Output\OutputInterface; |
| 69 | +use Symfony\Component\Console\Output\BufferedOutput; |
67 | 70 |
|
68 | 71 | use function Safe\putenv; |
69 | 72 |
|
@@ -215,6 +218,148 @@ public function constructorWillRegisterGlobalRuntimeOptions(): void |
215 | 218 | self::assertTrue($definition->hasOption('workspace-dir')); |
216 | 219 | self::assertSame('w', $definition->getOption('workspace-dir')->getShortcut()); |
217 | 220 | self::assertTrue($definition->hasOption('auto-update')); |
| 221 | + self::assertTrue($definition->hasOption('no-logo')); |
| 222 | + self::assertFalse($definition->getOption('no-logo')->acceptValue()); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * @return void |
| 227 | + */ |
| 228 | + #[Test] |
| 229 | + public function doRunWillRenderLogoUnlessNoLogoOptionIsProvided(): void |
| 230 | + { |
| 231 | + $input = new ArrayInput([ |
| 232 | + 'command' => 'list', |
| 233 | + ]); |
| 234 | + |
| 235 | + $output = new BufferedOutput(); |
| 236 | + |
| 237 | + $this->environment->get('FAST_FORWARD_AUTO_UPDATE', '') |
| 238 | + ->willReturn(''); |
| 239 | + $this->workingDirectorySwitcher->switchTo(null) |
| 240 | + ->shouldBeCalledOnce(); |
| 241 | + $this->versionCheckNotifier->notify($output) |
| 242 | + ->shouldBeCalledOnce(); |
| 243 | + |
| 244 | + $result = $this->invokeDoRun($input, $output); |
| 245 | + |
| 246 | + self::assertSame(Command::SUCCESS, $result); |
| 247 | + self::assertStringContainsString('_____', $output->fetch()); |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * @return void |
| 252 | + */ |
| 253 | + #[Test] |
| 254 | + public function doRunWillNotRenderLogoWhenNoLogoOptionIsSet(): void |
| 255 | + { |
| 256 | + $input = new ArrayInput([ |
| 257 | + '--no-logo' => true, |
| 258 | + 'command' => 'list', |
| 259 | + ]); |
| 260 | + |
| 261 | + $output = new BufferedOutput(); |
| 262 | + |
| 263 | + $this->environment->get('FAST_FORWARD_AUTO_UPDATE', '') |
| 264 | + ->willReturn(''); |
| 265 | + $this->workingDirectorySwitcher->switchTo(null) |
| 266 | + ->shouldBeCalledOnce(); |
| 267 | + $this->versionCheckNotifier->notify($output) |
| 268 | + ->shouldNotBeCalled(); |
| 269 | + |
| 270 | + $this->invokeDoRun($input, $output); |
| 271 | + |
| 272 | + self::assertStringNotContainsString('_____', $output->fetch()); |
| 273 | + } |
| 274 | + |
| 275 | + /** |
| 276 | + * @return void |
| 277 | + */ |
| 278 | + #[Test] |
| 279 | + public function doRunWillNotRenderLogoWhenJsonOptionIsProvided(): void |
| 280 | + { |
| 281 | + $command = new class extends Command { |
| 282 | + public function __construct() |
| 283 | + { |
| 284 | + parent::__construct('standards'); |
| 285 | + } |
| 286 | + |
| 287 | + protected function configure(): void |
| 288 | + { |
| 289 | + $this->addOption(name: 'json', mode: InputOption::VALUE_NONE, description: 'Emit structured JSON output.'); |
| 290 | + $this->setCode(static fn(InputInterface $input, OutputInterface $output): int => Command::SUCCESS); |
| 291 | + } |
| 292 | + }; |
| 293 | + |
| 294 | + $this->commandLoader->has('standards') |
| 295 | + ->willReturn(true) |
| 296 | + ->shouldBeCalledOnce(); |
| 297 | + $this->commandLoader->get('standards') |
| 298 | + ->willReturn($command) |
| 299 | + ->shouldBeCalledOnce(); |
| 300 | + $input = new ArrayInput([ |
| 301 | + 'command' => 'standards', |
| 302 | + '--json' => true, |
| 303 | + ]); |
| 304 | + |
| 305 | + $output = new BufferedOutput(); |
| 306 | + |
| 307 | + $this->environment->get('FAST_FORWARD_AUTO_UPDATE', '') |
| 308 | + ->willReturn(''); |
| 309 | + $this->workingDirectorySwitcher->switchTo(null) |
| 310 | + ->shouldBeCalledOnce(); |
| 311 | + $this->versionCheckNotifier->notify($output) |
| 312 | + ->shouldNotBeCalled(); |
| 313 | + |
| 314 | + $result = $this->invokeDoRun($input, $output); |
| 315 | + |
| 316 | + self::assertSame(Command::SUCCESS, $result); |
| 317 | + self::assertStringNotContainsString('_____', $output->fetch()); |
| 318 | + } |
| 319 | + |
| 320 | + /** |
| 321 | + * @return void |
| 322 | + */ |
| 323 | + #[Test] |
| 324 | + public function doRunWillNotRenderLogoWhenPrettyJsonOptionIsProvided(): void |
| 325 | + { |
| 326 | + $command = new class extends Command { |
| 327 | + public function __construct() |
| 328 | + { |
| 329 | + parent::__construct('standards'); |
| 330 | + } |
| 331 | + |
| 332 | + protected function configure(): void |
| 333 | + { |
| 334 | + $this->addOption(name: 'pretty-json', mode: InputOption::VALUE_NONE, description: 'Emit pretty JSON output.'); |
| 335 | + $this->setCode(static fn(InputInterface $input, OutputInterface $output): int => Command::SUCCESS); |
| 336 | + } |
| 337 | + }; |
| 338 | + |
| 339 | + $this->commandLoader->has('standards') |
| 340 | + ->willReturn(true) |
| 341 | + ->shouldBeCalledOnce(); |
| 342 | + $this->commandLoader->get('standards') |
| 343 | + ->willReturn($command) |
| 344 | + ->shouldBeCalledOnce(); |
| 345 | + $input = new ArrayInput([ |
| 346 | + 'command' => 'standards', |
| 347 | + '--pretty-json' => true, |
| 348 | + ]); |
| 349 | + |
| 350 | + $output = new BufferedOutput(); |
| 351 | + |
| 352 | + $this->environment->get('FAST_FORWARD_AUTO_UPDATE', '') |
| 353 | + ->willReturn(''); |
| 354 | + $this->workingDirectorySwitcher->switchTo(null) |
| 355 | + ->shouldBeCalledOnce(); |
| 356 | + $this->versionCheckNotifier->notify($output) |
| 357 | + ->shouldNotBeCalled(); |
| 358 | + |
| 359 | + $result = $this->invokeDoRun($input, $output); |
| 360 | + |
| 361 | + self::assertSame(Command::SUCCESS, $result); |
| 362 | + self::assertStringNotContainsString('_____', $output->fetch()); |
218 | 363 | } |
219 | 364 |
|
220 | 365 | /** |
@@ -404,4 +549,17 @@ private function invokeConfigureWorkspaceDirectory(InputInterface $input): void |
404 | 549 | $reflectionMethod = new ReflectionMethod($this->devTools, 'configureWorkspaceDirectory'); |
405 | 550 | $reflectionMethod->invoke($this->devTools, $input); |
406 | 551 | } |
| 552 | + |
| 553 | + /** |
| 554 | + * @param InputInterface $input |
| 555 | + * @param OutputInterface $output |
| 556 | + * |
| 557 | + * @return int |
| 558 | + */ |
| 559 | + private function invokeDoRun(InputInterface $input, OutputInterface $output): int |
| 560 | + { |
| 561 | + $reflectionMethod = new ReflectionMethod($this->devTools, 'doRun'); |
| 562 | + |
| 563 | + return (int) $reflectionMethod->invoke($this->devTools, $input, $output); |
| 564 | + } |
407 | 565 | } |
0 commit comments