|
37 | 37 | use Symfony\Component\Console\Input\InputDefinition;
|
38 | 38 | use Symfony\Component\Console\Input\InputInterface;
|
39 | 39 | use Symfony\Component\Console\Input\InputOption;
|
| 40 | +use Symfony\Component\Console\Output\BufferedOutput; |
40 | 41 | use Symfony\Component\Console\Output\ConsoleOutput;
|
41 | 42 | use Symfony\Component\Console\Output\NullOutput;
|
42 | 43 | use Symfony\Component\Console\Output\Output;
|
@@ -831,7 +832,7 @@ public function testSetCatchErrors(bool $catchExceptions)
|
831 | 832 |
|
832 | 833 | try {
|
833 | 834 | $tester->run(['command' => 'boom']);
|
834 |
| - $this->fail('The exception is not catched.'); |
| 835 | + $this->fail('The exception is not caught.'); |
835 | 836 | } catch (\Throwable $e) {
|
836 | 837 | $this->assertInstanceOf(\Error::class, $e);
|
837 | 838 | $this->assertSame('This is an error.', $e->getMessage());
|
@@ -2463,6 +2464,94 @@ private function createSignalableApplication(Command $command, ?EventDispatcherI
|
2463 | 2464 |
|
2464 | 2465 | return $application;
|
2465 | 2466 | }
|
| 2467 | + |
| 2468 | + public function testShellVerbosityIsRestoredAfterCommandExecutionWithInitialValue() |
| 2469 | + { |
| 2470 | + // Set initial SHELL_VERBOSITY |
| 2471 | + putenv('SHELL_VERBOSITY=-2'); |
| 2472 | + $_ENV['SHELL_VERBOSITY'] = '-2'; |
| 2473 | + $_SERVER['SHELL_VERBOSITY'] = '-2'; |
| 2474 | + |
| 2475 | + $application = new Application(); |
| 2476 | + $application->setAutoExit(false); |
| 2477 | + $application->register('foo') |
| 2478 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 2479 | + $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); |
| 2480 | + }); |
| 2481 | + |
| 2482 | + $input = new ArrayInput(['command' => 'foo', '--verbose' => 3]); |
| 2483 | + $output = new BufferedOutput(); |
| 2484 | + |
| 2485 | + $application->run($input, $output); |
| 2486 | + |
| 2487 | + $this->assertSame('SHELL_VERBOSITY: 3', $output->fetch()); |
| 2488 | + $this->assertSame('-2', getenv('SHELL_VERBOSITY')); |
| 2489 | + $this->assertSame('-2', $_ENV['SHELL_VERBOSITY']); |
| 2490 | + $this->assertSame('-2', $_SERVER['SHELL_VERBOSITY']); |
| 2491 | + |
| 2492 | + // Clean up for other tests |
| 2493 | + putenv('SHELL_VERBOSITY'); |
| 2494 | + unset($_ENV['SHELL_VERBOSITY']); |
| 2495 | + unset($_SERVER['SHELL_VERBOSITY']); |
| 2496 | + } |
| 2497 | + |
| 2498 | + public function testShellVerbosityIsRemovedAfterCommandExecutionWhenNotSetInitially() |
| 2499 | + { |
| 2500 | + // Ensure SHELL_VERBOSITY is not set initially |
| 2501 | + putenv('SHELL_VERBOSITY'); |
| 2502 | + unset($_ENV['SHELL_VERBOSITY']); |
| 2503 | + unset($_SERVER['SHELL_VERBOSITY']); |
| 2504 | + |
| 2505 | + $application = new Application(); |
| 2506 | + $application->setAutoExit(false); |
| 2507 | + $application->register('foo') |
| 2508 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 2509 | + $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); |
| 2510 | + }); |
| 2511 | + |
| 2512 | + $input = new ArrayInput(['command' => 'foo', '--verbose' => 3]); |
| 2513 | + $output = new BufferedOutput(); |
| 2514 | + |
| 2515 | + $application->run($input, $output); |
| 2516 | + |
| 2517 | + $this->assertSame('SHELL_VERBOSITY: 3', $output->fetch()); |
| 2518 | + $this->assertFalse(getenv('SHELL_VERBOSITY')); |
| 2519 | + $this->assertArrayNotHasKey('SHELL_VERBOSITY', $_ENV); |
| 2520 | + $this->assertArrayNotHasKey('SHELL_VERBOSITY', $_SERVER); |
| 2521 | + } |
| 2522 | + |
| 2523 | + public function testShellVerbosityDoesNotLeakBetweenCommandExecutions() |
| 2524 | + { |
| 2525 | + // Ensure no initial SHELL_VERBOSITY |
| 2526 | + putenv('SHELL_VERBOSITY'); |
| 2527 | + unset($_ENV['SHELL_VERBOSITY']); |
| 2528 | + unset($_SERVER['SHELL_VERBOSITY']); |
| 2529 | + |
| 2530 | + $application = new Application(); |
| 2531 | + $application->setAutoExit(false); |
| 2532 | + $application->register('verbose-cmd') |
| 2533 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 2534 | + $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); |
| 2535 | + }); |
| 2536 | + $application->register('normal-cmd') |
| 2537 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 2538 | + $output->write('SHELL_VERBOSITY: '.$_SERVER['SHELL_VERBOSITY']); |
| 2539 | + }); |
| 2540 | + |
| 2541 | + $output = new BufferedOutput(); |
| 2542 | + |
| 2543 | + $application->run(new ArrayInput(['command' => 'verbose-cmd', '--verbose' => true]), $output); |
| 2544 | + |
| 2545 | + $this->assertSame('SHELL_VERBOSITY: 1', $output->fetch(), 'SHELL_VERBOSITY should be set to 1 for verbose command'); |
| 2546 | + $this->assertFalse(getenv('SHELL_VERBOSITY'), 'SHELL_VERBOSITY should not be set after first command'); |
| 2547 | + |
| 2548 | + $application->run(new ArrayInput(['command' => 'normal-cmd']), $output); |
| 2549 | + |
| 2550 | + $this->assertSame('SHELL_VERBOSITY: 0', $output->fetch(), 'SHELL_VERBOSITY should not leak to second command'); |
| 2551 | + $this->assertFalse(getenv('SHELL_VERBOSITY'), 'SHELL_VERBOSITY should not leak to second command'); |
| 2552 | + $this->assertArrayNotHasKey('SHELL_VERBOSITY', $_ENV); |
| 2553 | + $this->assertArrayNotHasKey('SHELL_VERBOSITY', $_SERVER); |
| 2554 | + } |
2466 | 2555 | }
|
2467 | 2556 |
|
2468 | 2557 | class CustomApplication extends Application
|
|
0 commit comments