diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-20 05:21:19 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-20 05:21:19 +0900 |
| commit | a9070806935a105c69fc7ca255dc9002cf5c2d38 (patch) | |
| tree | 623a26aa077a926192fdf654f96740819aa47aec /crates/shirabe/tests/io/console_io_test.rs | |
| parent | dd06753ca61b9ccb64ac80e92390ee57d8f4b413 (diff) | |
| download | php-shirabe-a9070806935a105c69fc7ca255dc9002cf5c2d38.tar.gz php-shirabe-a9070806935a105c69fc7ca255dc9002cf5c2d38.tar.zst php-shirabe-a9070806935a105c69fc7ca255dc9002cf5c2d38.zip | |
test(console-io): un-ignore test_write_error via setErrorOutput
The ignore reason had rotted: ConsoleOutputInterface::set_error_output
is already ported, so a BufferedOutput error sink can be injected into
a real ConsoleOutput and the error-routed write read back, matching the
file's convention of replacing PHPUnit mock expectations with
BufferedOutput assertions.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/io/console_io_test.rs')
| -rw-r--r-- | crates/shirabe/tests/io/console_io_test.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/crates/shirabe/tests/io/console_io_test.rs b/crates/shirabe/tests/io/console_io_test.rs index 36ea4382..a924f0c7 100644 --- a/crates/shirabe/tests/io/console_io_test.rs +++ b/crates/shirabe/tests/io/console_io_test.rs @@ -21,6 +21,8 @@ use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::input::streamable_input_interface::StreamableInputInterface; use shirabe_external_packages::symfony::console::output::buffered_output::BufferedOutput; +use shirabe_external_packages::symfony::console::output::console_output::ConsoleOutput; +use shirabe_external_packages::symfony::console::output::console_output_interface::ConsoleOutputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::PhpMixed; @@ -106,13 +108,31 @@ fn test_write() { ); } -#[ignore = "PHP mocks ConsoleOutputInterface so getErrorOutput returns the same mock; a real ConsoleOutput's error StreamOutput writes to php://stderr, which cannot be read back, and the trait offers no seam to inject a BufferedOutput error sink"] #[test] fn test_write_error() { - // TODO(phase-d): PHP mocks ConsoleOutputInterface so getErrorOutput returns the same mock; a - // real ConsoleOutput's error StreamOutput writes to php://stderr, which cannot be read back, - // and the trait offers no seam to inject a BufferedOutput error sink. - todo!() + // PHP mocks ConsoleOutputInterface so getErrorOutput() returns the mock itself and expects + // write('some information about something', false) once at VERBOSITY_NORMAL. A real + // ConsoleOutput's error sink is stderr, which cannot be read back, but ConsoleOutputInterface + // includes setErrorOutput; swapping in a BufferedOutput error sink lets the error-routed + // write be read back, and writeError only ever reaches the sink returned by getErrorOutput. + let input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>> = std::rc::Rc::new( + std::cell::RefCell::new(ArrayInput::new(vec![], None).unwrap()), + ); + let console_output = ConsoleOutput::new(None, Some(false), None).unwrap(); + let error_buffer = std::rc::Rc::new(std::cell::RefCell::new(BufferedOutput::new( + None, false, None, + ))); + console_output.set_error_output(error_buffer.clone()); + let output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>> = + std::rc::Rc::new(std::cell::RefCell::new(console_output)); + let console_io = ConsoleIO::new(input, output, QuestionHelper::default()); + + console_io.write_error3("some information about something", false, NORMAL); + + assert_eq!( + "some information about something", + error_buffer.borrow().fetch() + ); } #[ignore = "ConsoleIO::write3 takes a single &str; the test feeds a 2-element array ['First line','Second lines'] and asserts a per-element regex on the debugging-prefixed messages array, which the &str signature cannot represent"] |
