From a9070806935a105c69fc7ca255dc9002cf5c2d38 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 20 Jul 2026 05:21:19 +0900 Subject: 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 --- crates/shirabe/tests/io/console_io_test.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'crates') 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::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::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"] -- cgit v1.3.1