|
13 | 13 | use OpenForgeProject\MageForge\Model\Config\Inspector as InspectorConfig; |
14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
15 | 15 | use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Component\Console\Output\OutputInterface; |
16 | 17 | use Symfony\Component\Console\Tester\CommandTester; |
17 | 18 |
|
18 | 19 | class InspectorCommandTest extends TestCase |
@@ -229,4 +230,83 @@ public function testStatusUppercasesActionArgument(): void |
229 | 230 | $this->assertSame(Cli::RETURN_SUCCESS, $exitCode); |
230 | 231 | $this->assertStringContainsString('MageForge Inspector Status', $tester->getDisplay()); |
231 | 232 | } |
| 233 | + |
| 234 | + // ------------------------------------------------------------------------- |
| 235 | + // No-argument execution path (interactive menu / non-interactive fallback) |
| 236 | + // ------------------------------------------------------------------------- |
| 237 | + |
| 238 | + public function testNoActionFallsBackToStatusInNonInteractiveMode(): void |
| 239 | + { |
| 240 | + $this->state->method('getMode')->willReturn(State::MODE_DEVELOPER); |
| 241 | + $this->scopeConfig->method('isSetFlag')->willReturn(true); |
| 242 | + $this->configWriter->expects($this->never())->method('save'); |
| 243 | + |
| 244 | + $tester = new CommandTester($this->command); |
| 245 | + $exitCode = $tester->execute([]); |
| 246 | + |
| 247 | + $this->assertSame(Cli::RETURN_SUCCESS, $exitCode); |
| 248 | + $this->assertStringContainsString('MageForge Inspector Status', $tester->getDisplay()); |
| 249 | + } |
| 250 | + |
| 251 | + public function testNoActionUsesSelectedActionFromInteractiveMenu(): void |
| 252 | + { |
| 253 | + $this->state->method('getMode')->willReturn(State::MODE_DEVELOPER); |
| 254 | + $this->configWriter->expects($this->once()) |
| 255 | + ->method('save') |
| 256 | + ->with(InspectorConfig::XML_PATH_ENABLED, '0'); |
| 257 | + |
| 258 | + $tester = new CommandTester($this->createInteractiveCommand('disable')); |
| 259 | + $exitCode = $tester->execute([]); |
| 260 | + |
| 261 | + $this->assertSame(Cli::RETURN_SUCCESS, $exitCode); |
| 262 | + $this->assertStringContainsString('has been disabled', $tester->getDisplay()); |
| 263 | + } |
| 264 | + |
| 265 | + public function testNoActionFailsWhenInteractiveMenuIsCancelled(): void |
| 266 | + { |
| 267 | + $this->configWriter->expects($this->never())->method('save'); |
| 268 | + |
| 269 | + $tester = new CommandTester($this->createInteractiveCommand(null)); |
| 270 | + $exitCode = $tester->execute([]); |
| 271 | + |
| 272 | + $this->assertSame(Cli::RETURN_FAILURE, $exitCode); |
| 273 | + } |
| 274 | + |
| 275 | + /** |
| 276 | + * Create a command double that always takes the interactive path and returns |
| 277 | + * the given selection from the menu instead of rendering a real prompt |
| 278 | + * |
| 279 | + * @param string|null $selection |
| 280 | + * @return InspectorCommand |
| 281 | + */ |
| 282 | + private function createInteractiveCommand(?string $selection): InspectorCommand |
| 283 | + { |
| 284 | + return new class( |
| 285 | + $this->configWriter, |
| 286 | + $this->state, |
| 287 | + $this->cacheManager, |
| 288 | + $this->scopeConfig, |
| 289 | + $selection, |
| 290 | + ) extends InspectorCommand { |
| 291 | + public function __construct( |
| 292 | + WriterInterface $configWriter, |
| 293 | + State $state, |
| 294 | + CacheManager $cacheManager, |
| 295 | + ScopeConfigInterface $scopeConfig, |
| 296 | + private readonly ?string $selection, |
| 297 | + ) { |
| 298 | + parent::__construct($configWriter, $state, $cacheManager, $scopeConfig); |
| 299 | + } |
| 300 | + |
| 301 | + protected function isInteractiveTerminal(OutputInterface $output): bool |
| 302 | + { |
| 303 | + return true; |
| 304 | + } |
| 305 | + |
| 306 | + protected function promptAction(): ?string |
| 307 | + { |
| 308 | + return $this->selection; |
| 309 | + } |
| 310 | + }; |
| 311 | + } |
232 | 312 | } |
0 commit comments