|
34 | 34 | use PHPUnit\Framework\Attributes\DataProvider; |
35 | 35 | use PHPUnit\Framework\Attributes\Group; |
36 | 36 | use ReflectionClass; |
| 37 | +use ReflectionProperty; |
37 | 38 | use Tests\Support\Commands\Modern\AppAboutCommand; |
38 | 39 | use Tests\Support\Commands\Modern\InteractFixtureCommand; |
39 | 40 | use Tests\Support\Commands\Modern\InteractiveStateProbeCommand; |
@@ -257,6 +258,74 @@ public function testCommandCanCallAnotherCommand(): void |
257 | 258 | $this->assertStringContainsString('help [options] [--] [<command_name>]', $this->getStreamFilterBuffer()); |
258 | 259 | } |
259 | 260 |
|
| 261 | + public function testCallSilentlySuppressesSubCommandOutputAndReturnsExitCode(): void |
| 262 | + { |
| 263 | + $command = new AppAboutCommand(new Commands()); |
| 264 | + |
| 265 | + $this->assertSame(EXIT_SUCCESS, $command->helpMeSilently()); |
| 266 | + $this->assertSame('', $this->getStreamFilterBuffer()); |
| 267 | + } |
| 268 | + |
| 269 | + public function testCallSilentlyRestoresPriorIo(): void |
| 270 | + { |
| 271 | + $custom = new InputOutput(); |
| 272 | + CLI::setInputOutput($custom); |
| 273 | + |
| 274 | + $command = new AppAboutCommand(new Commands()); |
| 275 | + $command->helpMeSilently(); |
| 276 | + |
| 277 | + $this->assertSame($custom, CLI::getInputOutput()); |
| 278 | + } |
| 279 | + |
| 280 | + public function testCallSilentlyResetsToFreshInputOutputWhenPriorWasNull(): void |
| 281 | + { |
| 282 | + $property = new ReflectionProperty(CLI::class, 'io'); |
| 283 | + $property->setValue(null, null); |
| 284 | + |
| 285 | + $command = new AppAboutCommand(new Commands()); |
| 286 | + $command->helpMeSilently(); |
| 287 | + |
| 288 | + $current = CLI::getInputOutput(); |
| 289 | + $this->assertInstanceOf(InputOutput::class, $current); |
| 290 | + $this->assertNotInstanceOf(NullInputOutput::class, $current); |
| 291 | + } |
| 292 | + |
| 293 | + public function testCallSilentlyPropagatesSubCommandNonZeroExitCode(): void |
| 294 | + { |
| 295 | + $command = new AppAboutCommand(new Commands()); |
| 296 | + |
| 297 | + $this->assertSame(EXIT_ERROR, $command->callUnknownSilently()); |
| 298 | + $this->assertSame('', $this->getStreamFilterBuffer()); |
| 299 | + } |
| 300 | + |
| 301 | + public function testCallSilentlyRestoresPriorLastWriteState(): void |
| 302 | + { |
| 303 | + CLI::setLastWrite(null); |
| 304 | + |
| 305 | + $command = new AppAboutCommand(new Commands()); |
| 306 | + $command->helpMeSilently(); |
| 307 | + |
| 308 | + $this->assertNull( |
| 309 | + CLI::getLastWrite(), |
| 310 | + 'callSilently() must not leak the silenced sub-command\'s $lastWrite mutation back to the parent.', |
| 311 | + ); |
| 312 | + } |
| 313 | + |
| 314 | + public function testCallSilentlyForwardsNoInteractionOverrideFalseToChild(): void |
| 315 | + { |
| 316 | + $command = new ParentCallsInteractFixtureCommand(new Commands()); |
| 317 | + $command->setInteractive(false); |
| 318 | + $command->useCallSilently = true; |
| 319 | + $command->childNoInteractionOverride = false; |
| 320 | + |
| 321 | + $exitCode = $command->run([], []); |
| 322 | + |
| 323 | + $this->assertSame(EXIT_SUCCESS, $exitCode); |
| 324 | + $this->assertFalse($command->isInteractive()); |
| 325 | + $this->assertTrue(InteractiveStateProbeCommand::$interactCalled); |
| 326 | + $this->assertTrue(InteractiveStateProbeCommand::$observedInteractive); |
| 327 | + } |
| 328 | + |
260 | 329 | public function testRunCommand(): void |
261 | 330 | { |
262 | 331 | command('app:about a'); |
|
0 commit comments