diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 03:46:41 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 03:46:41 +0900 |
| commit | 92d2199afcecd0056e82d2559700769715401ef0 (patch) | |
| tree | b9d65620db53bc19f800247660e560f3f8775217 /crates/shirabe/tests | |
| parent | 27e81d5e5ca0a89eb176a65b1d9f186658b16f50 (diff) | |
| download | php-shirabe-92d2199afcecd0056e82d2559700769715401ef0.tar.gz php-shirabe-92d2199afcecd0056e82d2559700769715401ef0.tar.zst php-shirabe-92d2199afcecd0056e82d2559700769715401ef0.zip | |
refactor(php-shim): take filesystem paths as impl AsRef<Path>
The shim's filesystem entry points took `&str` even though each one resolves
to a local path through `std::fs` or a syscall, so callers holding a `PathBuf`
had to stringify it at the call site. They now take `impl AsRef<Path>`, the
form `file_exists`, `is_dir`, `unlink` and the rest of the already-converted
set use.
`Phar`, `PharData` and `ZipArchive` keep their archive path as a `PathBuf`.
`PharData::compress` names the compressed sibling by appending the suffix to
the file name rather than formatting the path into a `String`.
Arguments PHP resolves through a stream wrapper (`fopen`, `file_put_contents`,
`include`) still take `&str`, as do the byte-string operations (`dirname`,
`basename`, `pathinfo`) and archive-internal entry names, which are `/`-joined
logical names rather than OS paths.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
7 files changed, 21 insertions, 21 deletions
diff --git a/crates/shirabe/tests/command/bump_command_test.rs b/crates/shirabe/tests/command/bump_command_test.rs index 14ac17a6..a7cdfd76 100644 --- a/crates/shirabe/tests/command/bump_command_test.rs +++ b/crates/shirabe/tests/command/bump_command_test.rs @@ -243,7 +243,7 @@ fn test_bump_fails_on_write_error_to_composer_file() { let tear_down = init_temp_composer(Some(&serde_json::json!({})), None, None, false); let composer_json_path = tear_down.working_dir().join("composer.json"); - shirabe_php_shim::chmod(&composer_json_path.to_string_lossy(), 0o444); + shirabe_php_shim::chmod(&composer_json_path, 0o444); let mut app_tester = get_application_tester(); let status_code = app_tester diff --git a/crates/shirabe/tests/command/validate_command_test.rs b/crates/shirabe/tests/command/validate_command_test.rs index c40f66b2..8e78dfe7 100644 --- a/crates/shirabe/tests/command/validate_command_test.rs +++ b/crates/shirabe/tests/command/validate_command_test.rs @@ -163,7 +163,7 @@ fn test_unaccessible_file() { let tear_down = init_temp_composer(Some(&minimal_valid_configuration()), None, None, true); let composer_json = tear_down.working_dir().join("composer.json"); - shirabe_php_shim::chmod(&composer_json.to_string_lossy(), 0o200); + shirabe_php_shim::chmod(&composer_json, 0o200); let mut app_tester = get_application_tester(); app_tester @@ -176,6 +176,6 @@ fn test_unaccessible_file() { ); assert_eq!(3, app_tester.get_status_code()); - shirabe_php_shim::chmod(&composer_json.to_string_lossy(), 0o700); + shirabe_php_shim::chmod(&composer_json, 0o700); drop(tear_down); } diff --git a/crates/shirabe/tests/installed_versions_test.rs b/crates/shirabe/tests/installed_versions_test.rs index 4de2730d..7257ff6a 100644 --- a/crates/shirabe/tests/installed_versions_test.rs +++ b/crates/shirabe/tests/installed_versions_test.rs @@ -402,7 +402,7 @@ fn test_get_install_path() { assert_eq!( realpath(&dir), realpath( - &InstalledVersions::get_install_path("__root__") + InstalledVersions::get_install_path("__root__") .unwrap() .unwrap() ) diff --git a/crates/shirabe/tests/package/archiver/phar_archiver_test.rs b/crates/shirabe/tests/package/archiver/phar_archiver_test.rs index 7d879973..a9163058 100644 --- a/crates/shirabe/tests/package/archiver/phar_archiver_test.rs +++ b/crates/shirabe/tests/package/archiver/phar_archiver_test.rs @@ -53,7 +53,7 @@ impl ArchiverTestCase { fn write_file(&self, path: &str, content: &str, current_work_dir: &str) { if !file_exists(dirname(path)) { - mkdir(&dirname(path), 0o777, true); + mkdir(dirname(path), 0o777, true); } let result = file_put_contents(path, content.as_bytes()); diff --git a/crates/shirabe/tests/package/archiver/zip_archiver_test.rs b/crates/shirabe/tests/package/archiver/zip_archiver_test.rs index b94beb6c..e20ca624 100644 --- a/crates/shirabe/tests/package/archiver/zip_archiver_test.rs +++ b/crates/shirabe/tests/package/archiver/zip_archiver_test.rs @@ -106,7 +106,7 @@ impl ArchiverTestCase { fn write_file(&self, path: &str, content: String, current_work_dir: &str) { if !file_exists(dirname(path)) { - mkdir(&dirname(path), 0o777, true); + mkdir(dirname(path), 0o777, true); } let result = file_put_contents(path, content.as_bytes()); diff --git a/crates/shirabe/tests/repository/path_repository_test.rs b/crates/shirabe/tests/repository/path_repository_test.rs index 24bf64d5..0631e7f7 100644 --- a/crates/shirabe/tests/repository/path_repository_test.rs +++ b/crates/shirabe/tests/repository/path_repository_test.rs @@ -201,7 +201,7 @@ fn test_url_remains_relative() { // realpath() does not fully expand the paths // PHP Bug https://bugs.php.net/bug.php?id=72642 let repository_url = [ - realpath(&realpath(&fixtures_dir().replace("/Fixtures", "")).unwrap_or_default()) + realpath(realpath(fixtures_dir().replace("/Fixtures", "")).unwrap_or_default()) .unwrap_or_default(), "Fixtures".to_string(), "path".to_string(), @@ -210,7 +210,7 @@ fn test_url_remains_relative() { .join(DIRECTORY_SEPARATOR); // getcwd() not necessarily match __DIR__ // PHP Bug https://bugs.php.net/bug.php?id=73797 - let cwd = realpath(&realpath(&Platform::get_cwd(false).unwrap()).unwrap_or_default()) + let cwd = realpath(realpath(Platform::get_cwd(false).unwrap()).unwrap_or_default()) .unwrap_or_default(); let relative_url = repository_url[cwd.len().min(repository_url.len())..] .trim_start_matches(DIRECTORY_SEPARATOR) diff --git a/crates/shirabe/tests/util/filesystem_test.rs b/crates/shirabe/tests/util/filesystem_test.rs index 2e160e87..5bb44598 100644 --- a/crates/shirabe/tests/util/filesystem_test.rs +++ b/crates/shirabe/tests/util/filesystem_test.rs @@ -433,7 +433,7 @@ fn test_remove_directory_php() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/level1/level2"), 0o777, true); + mkdir(format!("{working_dir}/level1/level2"), 0o777, true); file_put_contents( &format!("{working_dir}/level1/level2/hello.txt"), b"hello world", @@ -509,10 +509,10 @@ fn test_unlink_symlinked_directory() { let working_dir = tempfile::TempDir::new().unwrap(); let basepath = working_dir.path().to_str().unwrap().to_string(); let symlinked = format!("{basepath}/linked"); - mkdir(&format!("{basepath}/real"), 0o777, true); - touch(&format!("{basepath}/real/FILE")); + mkdir(format!("{basepath}/real"), 0o777, true); + touch(format!("{basepath}/real/FILE")); - let result = symlink(&format!("{basepath}/real"), &symlinked); + let result = symlink(format!("{basepath}/real"), &symlinked); if !result { // Symbolic links for directories not supported on this platform. @@ -534,12 +534,12 @@ fn test_remove_symlinked_directory_with_trailing_slash() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real"), 0o777, true); - touch(&format!("{working_dir}/real/FILE")); + mkdir(format!("{working_dir}/real"), 0o777, true); + touch(format!("{working_dir}/real/FILE")); let symlinked = format!("{working_dir}/linked"); let symlinked_trailing_slash = format!("{symlinked}/"); - let result = symlink(&format!("{working_dir}/real"), &symlinked); + let result = symlink(format!("{working_dir}/real"), &symlinked); if !result { // Symbolic links for directories not supported on this platform. @@ -567,7 +567,7 @@ fn test_junctions() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real/nesting/testing"), 0o777, true); + mkdir(format!("{working_dir}/real/nesting/testing"), 0o777, true); let mut fs = Filesystem::new(None); // Non-Windows systems do not support this and will return false on all tests, and an exception @@ -625,7 +625,7 @@ fn test_override_junctions() { let working_dir = tempfile::TempDir::new().unwrap(); let working_dir = working_dir.path().to_str().unwrap().to_string(); - mkdir(&format!("{working_dir}/real/nesting/testing"), 0o777, true); + mkdir(format!("{working_dir}/real/nesting/testing"), 0o777, true); let mut fs = Filesystem::new(None); let old_target = format!("{working_dir}/real/nesting/testing"); @@ -667,8 +667,8 @@ fn test_copy() { let unique_tmp = tempfile::TempDir::new().unwrap(); let test_file = format!("{}/composer_test_file", unique_tmp.path().to_str().unwrap()); - mkdir(&format!("{working_dir}/foo/bar"), 0o777, true); - mkdir(&format!("{working_dir}/foo/baz"), 0o777, true); + mkdir(format!("{working_dir}/foo/bar"), 0o777, true); + mkdir(format!("{working_dir}/foo/baz"), 0o777, true); file_put_contents(&format!("{working_dir}/foo/foo.file"), b"foo"); file_put_contents(&format!("{working_dir}/foo/bar/foobar.file"), b"foobar"); file_put_contents(&format!("{working_dir}/foo/baz/foobaz.file"), b"foobaz"); @@ -722,8 +722,8 @@ fn test_copy_then_remove() { let unique_tmp = tempfile::TempDir::new().unwrap(); let test_file = format!("{}/composer_test_file", unique_tmp.path().to_str().unwrap()); - mkdir(&format!("{working_dir}/foo/bar"), 0o777, true); - mkdir(&format!("{working_dir}/foo/baz"), 0o777, true); + mkdir(format!("{working_dir}/foo/bar"), 0o777, true); + mkdir(format!("{working_dir}/foo/baz"), 0o777, true); file_put_contents(&format!("{working_dir}/foo/foo.file"), b"foo"); file_put_contents(&format!("{working_dir}/foo/bar/foobar.file"), b"foobar"); file_put_contents(&format!("{working_dir}/foo/baz/foobaz.file"), b"foobaz"); |
