diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-07 07:01:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-07 07:01:50 +0900 |
| commit | 759b2980e70dfb8960238f75d68bb6dddce25414 (patch) | |
| tree | e37a0af6423f8ae8dd26da309b278d49d45b3451 /crates/shirabe/tests/util | |
| parent | 9a393adc0ace86cac788723b524e83c63dfc91c1 (diff) | |
| download | php-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.tar.gz php-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.tar.zst php-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.zip | |
test: port the tests left as todo!() stubs
Replace the todo!() bodies with real ports. Four autoload-generator
tests now run for real; the rest stay #[ignore]d, but each ignore reason
now names the concrete missing symbol instead of a vague subsystem.
Production additions the ports need: the deprecated
AuthHelper::addAuthenticationHeader wrapper,
EventDispatcher::__set_dispatch_script_override as the seam for PHPUnit
onlyMethods(['dispatchScript']), and a define() stub in the shim.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util')
| -rw-r--r-- | crates/shirabe/tests/util/auth_helper_test.rs | 50 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/error_handler_test.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/process_executor_test.rs | 48 |
3 files changed, 69 insertions, 38 deletions
diff --git a/crates/shirabe/tests/util/auth_helper_test.rs b/crates/shirabe/tests/util/auth_helper_test.rs index 91d9cb75..ef5daaf7 100644 --- a/crates/shirabe/tests/util/auth_helper_test.rs +++ b/crates/shirabe/tests/util/auth_helper_test.rs @@ -757,16 +757,48 @@ fn test_prompt_auth_if_needed_multiple_bitbucket_downloads() { } #[test] -#[ignore = "exercises the deprecated addAuthenticationHeader wrapper (not ported) which relies on \ -trigger_error/E_USER_DEPRECATED; the PHP error-handler subsystem is not modeled"] +#[ignore = "addAuthenticationHeader opens with trigger_error(E_USER_DEPRECATED), and \ +shirabe_php_shim::trigger_error is a todo!()"] fn test_add_authentication_header_with_custom_headers() { - // TODO(phase-d): exercises AuthHelper::addAuthenticationHeader, a deprecated wrapper - // around addAuthenticationOptions that PHP implements via - // trigger_error(E_USER_DEPRECATED). It has not been ported to Rust (no - // add_authentication_header method exists on AuthHelper) because the PHP - // error-handler subsystem it relies on is not modeled — same limitation as - // error_handler_test.rs. - todo!() + let mut f = set_up(); + let headers = vec![ + "Accept-Encoding: gzip".to_string(), + "Connection: close".to_string(), + ]; + let origin = "example.org"; + let url = "https://example.org/packages.json"; + let custom_headers = vec![ + "API-TOKEN: abc123".to_string(), + "X-CUSTOM-HEADER: value".to_string(), + ]; + let headers_json = json_encode(&PhpMixed::List( + custom_headers + .iter() + .map(|h| PhpMixed::String(h.clone())) + .collect(), + )) + .unwrap(); + + expects_authentication(&f.io, origin, &headers_json, "custom-headers"); + + f.io.borrow_mut() + .expects( + vec![Expectation::text( + "Using custom HTTP headers for authentication", + )], + true, + ) + .unwrap(); + + let mut expected_headers = headers.clone(); + expected_headers.extend(custom_headers); + + assert_eq!( + expected_headers, + f.auth_helper + .add_authentication_header(headers, origin, url) + .unwrap() + ); } #[test] diff --git a/crates/shirabe/tests/util/error_handler_test.rs b/crates/shirabe/tests/util/error_handler_test.rs index ed5e6a29..efaf4e11 100644 --- a/crates/shirabe/tests/util/error_handler_test.rs +++ b/crates/shirabe/tests/util/error_handler_test.rs @@ -5,16 +5,17 @@ // trigger those by undefined-index access / array_merge misuse. There is no equivalent // runtime mechanism in Rust to port faithfully. -// TODO(phase-d): ErrorHandler::register() installs a PHP set_error_handler; no Rust equivalent. +use shirabe::util::ErrorHandler; +use shirabe_php_shim::restore_error_handler; + #[allow(dead_code)] fn set_up() { - todo!() + ErrorHandler::register(None); } -// TODO(phase-d): restore_error_handler() is PHP runtime machinery; no Rust equivalent. #[allow(dead_code)] fn tear_down() { - todo!() + restore_error_handler(); } #[allow(dead_code)] diff --git a/crates/shirabe/tests/util/process_executor_test.rs b/crates/shirabe/tests/util/process_executor_test.rs index 2ce43f3c..268bc548 100644 --- a/crates/shirabe/tests/util/process_executor_test.rs +++ b/crates/shirabe/tests/util/process_executor_test.rs @@ -15,7 +15,7 @@ use shirabe_external_packages::symfony::console::output::buffered_output::Buffer use shirabe_external_packages::symfony::console::output::output_interface::{ OutputInterface, VERBOSITY_DEBUG, VERBOSITY_NORMAL, }; -use shirabe_php_shim::{PHP_EOL, trim}; +use shirabe_php_shim::{PHP_EOL, ob_get_clean, ob_start, trim}; #[test] fn test_execute_captures_output() { @@ -25,16 +25,16 @@ fn test_execute_captures_output() { assert_eq!(format!("foo{}", PHP_EOL), output); } -#[ignore = "requires PHP output buffering (ob_start/ob_get_clean) to capture stdout; no equivalent symbol"] +#[ignore = "shirabe_php_shim::ob_start/ob_get_clean are todo!(): the shim has no echo-to-buffer routing, and ProcessExecutor::execute with FORWARD_OUTPUT and io=None writes straight to the real process stdout"] #[test] fn test_execute_outputs_if_not_captured() { - // TODO(phase-d): requires PHP output buffering (ob_start/ob_get_clean) to capture - // stdout; no equivalent symbol. ProcessExecutor::execute with - // ProcessExecutor::FORWARD_OUTPUT and io=None writes straight to the real process - // stdout (see output_handler's `print!`), and there is no safe way to capture that - // from within a parallel cargo test process without redirecting the real stdout file - // descriptor, which is unsafe under `cargo test`'s default multi-threaded runner. - todo!() + let mut process = ProcessExecutor::new(None); + ob_start(); + process + .execute("echo foo", ProcessExecutor::FORWARD_OUTPUT, None) + .unwrap(); + let output = ob_get_clean(); + assert_eq!(Some(format!("foo{}", PHP_EOL)), output); } #[test] @@ -139,18 +139,17 @@ fn test_doesnt_hide_ports() { ); } -#[ignore = "splitLines is called with null in the PHP test, but split_lines accepts only &str (no ?string/Option overload)"] #[test] fn test_split_lines() { - // TODO(phase-d): splitLines is called with null in the PHP test - // ($process->splitLines(null)), but ProcessExecutor::split_lines here takes `&str`, not - // `Option<&str>` (PHP's `?string`). Porting this data point faithfully means widening - // split_lines's signature to Option<&str>, which touches every call site - // (package/version/version_guesser.rs, util/git.rs, - // repository/vcs/{hg,fossil,git,svn}_driver.rs — 13 call sites in total, all currently - // passing `&str`). That is a production API change beyond this test file; flagged for - // a design decision rather than made unilaterally. - todo!() + let process = ProcessExecutor::new(None); + assert!(process.split_lines("").is_empty()); + // PHP: $process->splitLines(null). `split_lines` takes `&str` where PHP takes `?string`, and + // its body opens with `trim((string) $output)`, so the caller performs the null-to-"" cast. + assert!(process.split_lines("").is_empty()); + assert_eq!(vec!["foo"], process.split_lines("foo")); + assert_eq!(vec!["foo", "bar"], process.split_lines("foo\nbar")); + assert_eq!(vec!["foo", "bar"], process.split_lines("foo\r\nbar")); + assert_eq!(vec!["foo", "bar"], process.split_lines("foo\r\nbar\n")); } #[test] @@ -185,14 +184,13 @@ fn test_console_io_does_not_format_symfony_console_style() { ); } -#[ignore = "executeAsync returns a Process, not a cancelable promise; no promise/cancel symbol exists"] +#[ignore = "none of the three symbols this test drives exist: execute_async returns a plain future with no cancel(), and ProcessExecutor has no count_active_jobs or wait (PHP's $jobs/$maxJobs queue is a tokio semaphore here)"] #[test] fn test_execute_async_cancel() { - // TODO(phase-d): PHP's executeAsync returns a React\Promise\PromiseInterface with - // cancel(); Rust's execute_async returns anyhow::Result<Process> directly (see the - // comment on ProcessExecutor::execute_async: "no test seam in the external-packages - // crate"), so there is no promise/cancel symbol to drive this test's - // `$promise->cancel()` step. + // TODO(phase-d): PHP's executeAsync returns a React\Promise\PromiseInterface with cancel(), + // and the test reads countActiveJobs() around it and then calls wait(). execute_async here + // returns a plain future with no cancel(), and ProcessExecutor has neither count_active_jobs + // nor wait: the PHP job queue those methods expose is a tokio semaphore in this port. todo!() } |
