|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Console\Tests\Tester; |
13 | 13 |
|
| 14 | +use PHPUnit\Framework\Attributes\DataProvider; |
14 | 15 | use PHPUnit\Framework\TestCase; |
15 | 16 | use Symfony\Component\Console\Application; |
16 | 17 | use Symfony\Component\Console\Helper\QuestionHelper; |
@@ -91,6 +92,46 @@ public function testGetStatusCode() |
91 | 92 | $this->tester->assertCommandIsSuccessful('->getStatusCode() returns the status code'); |
92 | 93 | } |
93 | 94 |
|
| 95 | + #[DataProvider('provideShellVerbositySources')] |
| 96 | + public function testShellVerbosityDoesNotOverrideInteractiveAndVerbosity(callable $setShellVerbosity, callable $cleanUp) |
| 97 | + { |
| 98 | + $setShellVerbosity(); |
| 99 | + |
| 100 | + try { |
| 101 | + $application = new Application(); |
| 102 | + $application->setAutoExit(false); |
| 103 | + $application->register('foo') |
| 104 | + ->setCode(static function ($input, $output) { |
| 105 | + $output->writeln('foo'); |
| 106 | + }) |
| 107 | + ; |
| 108 | + |
| 109 | + $tester = new ApplicationTester($application); |
| 110 | + $tester->run(['command' => 'foo'], ['interactive' => true]); |
| 111 | + |
| 112 | + $this->assertTrue($tester->getInput()->isInteractive()); |
| 113 | + $this->assertSame('foo'.\PHP_EOL, $tester->getDisplay()); |
| 114 | + } finally { |
| 115 | + $cleanUp(); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + public static function provideShellVerbositySources(): iterable |
| 120 | + { |
| 121 | + yield 'putenv' => [ |
| 122 | + static function () { putenv('SHELL_VERBOSITY=-1'); }, |
| 123 | + static function () { putenv('SHELL_VERBOSITY'); }, |
| 124 | + ]; |
| 125 | + yield '$_ENV' => [ |
| 126 | + static function () { $_ENV['SHELL_VERBOSITY'] = '-1'; }, |
| 127 | + static function () { unset($_ENV['SHELL_VERBOSITY']); }, |
| 128 | + ]; |
| 129 | + yield '$_SERVER' => [ |
| 130 | + static function () { $_SERVER['SHELL_VERBOSITY'] = '-1'; }, |
| 131 | + static function () { unset($_SERVER['SHELL_VERBOSITY']); }, |
| 132 | + ]; |
| 133 | + } |
| 134 | + |
94 | 135 | public function testErrorOutput() |
95 | 136 | { |
96 | 137 | $application = new Application(); |
|
0 commit comments