inputs = $inputs; } /** * Add input to the queue */ public function addInput(string $input): self { $this->inputs[] = $input; return $this; } /** * Add multiple inputs */ public function addInputs(array $inputs): self { foreach ($inputs as $input) { $this->addInput($input); } return $this; } /** * Activate the mock (replace STDIN) */ public function activate(): void { if ($this->isActive) { return; } // Create a temporary file for input $tempFile = tmpfile(); if ($tempFile === false) { throw new \RuntimeException('Could not create temporary file for STDIN mock'); } // Write all inputs to the temp file $content = implode("\n", $this->inputs) . "\n"; fwrite($tempFile, $content); rewind($tempFile); // Store original STDIN if we can if (defined('STDIN') && is_resource(STDIN)) { $this->originalStdin = STDIN; } // Replace STDIN constant (not possible in PHP, so we use a workaround) // We'll need to use a different approach - create a stream wrapper $this->isActive = true; } /** * Deactivate the mock (restore original STDIN) */ public function deactivate(): void { if (!$this->isActive) { return; } $this->isActive = false; } /** * Get next input (simulates fgets) */ public function getNextInput(): ?string { if ($this->currentIndex >= count($this->inputs)) { return null; } $input = $this->inputs[$this->currentIndex]; $this->currentIndex++; return $input . "\n"; } /** * Reset to beginning */ public function reset(): void { $this->currentIndex = 0; } /** * Check if there are more inputs */ public function hasMoreInputs(): bool { return $this->currentIndex < count($this->inputs); } /** * Get all remaining inputs */ public function getRemainingInputs(): array { return array_slice($this->inputs, $this->currentIndex); } }