|
37 | 37 | use Tests\Support\Commands\Modern\AppAboutCommand; |
38 | 38 | use Tests\Support\Duplicates\DuplicateLegacy; |
39 | 39 | use Tests\Support\Duplicates\DuplicateModern; |
| 40 | +use Tests\Support\Duplicates\HiddenDuplicateModern; |
40 | 41 | use Tests\Support\InvalidCommands\AliasClashCommand; |
41 | 42 | use Tests\Support\InvalidCommands\AliasSecondClashCommand; |
42 | 43 | use Tests\Support\InvalidCommands\AliasTargetCommand; |
@@ -349,6 +350,131 @@ public function testRunCommandViaAlias(): void |
349 | 350 | $this->assertStringContainsString('Ran fixture:aliased.', $this->getStreamFilterBuffer()); |
350 | 351 | } |
351 | 352 |
|
| 353 | + public function testHiddenCommandIsRegisteredWithItsFlag(): void |
| 354 | + { |
| 355 | + $commands = (new Commands())->getModernCommands(); |
| 356 | + |
| 357 | + $this->assertTrue($commands['fixture:hidden']['hidden']); |
| 358 | + $this->assertFalse($commands['fixture:aliased']['hidden']); |
| 359 | + } |
| 360 | + |
| 361 | + public function testIsHiddenCommand(): void |
| 362 | + { |
| 363 | + $commands = new Commands(); |
| 364 | + |
| 365 | + $this->assertTrue($commands->isHiddenCommand('fixture:hidden')); |
| 366 | + $this->assertTrue($commands->isHiddenCommand('fixture:secret')); |
| 367 | + $this->assertFalse($commands->isHiddenCommand('fixture:aliased')); |
| 368 | + $this->assertFalse($commands->isHiddenCommand('fixture:alias')); |
| 369 | + $this->assertFalse($commands->isHiddenCommand('app:info')); |
| 370 | + $this->assertFalse($commands->isHiddenCommand('app:unknown')); |
| 371 | + } |
| 372 | + |
| 373 | + public function testIsHiddenCommandIsFalseWhenLegacyCommandShadowsIt(): void |
| 374 | + { |
| 375 | + $this->injectFixtureLocator([ |
| 376 | + DuplicateLegacy::class => SUPPORTPATH . 'Duplicates/DuplicateLegacy.php', |
| 377 | + HiddenDuplicateModern::class => SUPPORTPATH . 'Duplicates/HiddenDuplicateModern.php', |
| 378 | + ]); |
| 379 | + |
| 380 | + $this->assertFalse((new Commands())->isHiddenCommand('dup:test')); |
| 381 | + } |
| 382 | + |
| 383 | + public function testHiddenCommandRunsByName(): void |
| 384 | + { |
| 385 | + command('fixture:hidden'); |
| 386 | + |
| 387 | + $this->assertSame( |
| 388 | + <<<'EOT' |
| 389 | +
|
| 390 | + Ran fixture:hidden. |
| 391 | + |
| 392 | + EOT, |
| 393 | + $this->getUndecoratedBuffer(), |
| 394 | + ); |
| 395 | + } |
| 396 | + |
| 397 | + public function testHiddenCommandRunsByAlias(): void |
| 398 | + { |
| 399 | + command('fixture:secret'); |
| 400 | + |
| 401 | + $this->assertSame( |
| 402 | + <<<'EOT' |
| 403 | +
|
| 404 | + Ran fixture:hidden. |
| 405 | + |
| 406 | + EOT, |
| 407 | + $this->getUndecoratedBuffer(), |
| 408 | + ); |
| 409 | + } |
| 410 | + |
| 411 | + public function testHiddenCommandRunsThroughModernCall(): void |
| 412 | + { |
| 413 | + $commands = new Commands(); |
| 414 | + $call = $this->getPrivateMethodInvoker(new AliasedCommand($commands), 'call'); |
| 415 | + |
| 416 | + $this->assertSame(EXIT_SUCCESS, $call('fixture:hidden')); |
| 417 | + $this->assertSame(EXIT_SUCCESS, $call('fixture:secret')); |
| 418 | + $this->assertSame( |
| 419 | + <<<'EOT' |
| 420 | +
|
| 421 | + Ran fixture:hidden. |
| 422 | + Ran fixture:hidden. |
| 423 | + |
| 424 | + EOT, |
| 425 | + $this->getUndecoratedBuffer(), |
| 426 | + ); |
| 427 | + } |
| 428 | + |
| 429 | + public function testHiddenCommandRunsThroughLegacyCall(): void |
| 430 | + { |
| 431 | + $commands = new Commands(); |
| 432 | + $call = $this->getPrivateMethodInvoker(new AppInfo(service('logger'), $commands), 'call'); |
| 433 | + |
| 434 | + $this->assertSame(EXIT_SUCCESS, $call('fixture:hidden')); |
| 435 | + $this->assertSame(EXIT_SUCCESS, $call('fixture:secret')); |
| 436 | + $this->assertSame( |
| 437 | + <<<'EOT' |
| 438 | +
|
| 439 | + Ran fixture:hidden. |
| 440 | + Ran fixture:hidden. |
| 441 | + |
| 442 | + EOT, |
| 443 | + $this->getUndecoratedBuffer(), |
| 444 | + ); |
| 445 | + } |
| 446 | + |
| 447 | + public function testHiddenCommandAndItsAliasesAreNotSuggested(): void |
| 448 | + { |
| 449 | + $this->assertSame(['fixture:alias', 'fixture:aliased'], (new Commands())->getCommandAlternatives('fixture:')); |
| 450 | + } |
| 451 | + |
| 452 | + public function testMistypedHiddenCommandIsReportedWithoutSuggestion(): void |
| 453 | + { |
| 454 | + $commands = new Commands(); |
| 455 | + |
| 456 | + $this->assertSame([], $commands->getCommandAlternatives('fixture:secre')); |
| 457 | + $this->assertSame(EXIT_ERROR, $commands->runCommand('fixture:hiddenn', [], [])); |
| 458 | + $this->assertSame( |
| 459 | + <<<'EOT' |
| 460 | +
|
| 461 | + Command "fixture:hiddenn" not found. |
| 462 | + |
| 463 | + EOT, |
| 464 | + $this->getUndecoratedBuffer(), |
| 465 | + ); |
| 466 | + } |
| 467 | + |
| 468 | + public function testLegacyCommandShadowingHiddenModernCommandIsStillSuggested(): void |
| 469 | + { |
| 470 | + $this->injectFixtureLocator([ |
| 471 | + DuplicateLegacy::class => SUPPORTPATH . 'Duplicates/DuplicateLegacy.php', |
| 472 | + HiddenDuplicateModern::class => SUPPORTPATH . 'Duplicates/HiddenDuplicateModern.php', |
| 473 | + ]); |
| 474 | + |
| 475 | + $this->assertSame(['dup:test'], (new Commands())->getCommandAlternatives('dup:tes')); |
| 476 | + } |
| 477 | + |
352 | 478 | public function testAliasClashingWithCommandNameFailsHard(): void |
353 | 479 | { |
354 | 480 | $this->injectFixtureLocator([ |
|
0 commit comments