aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-22 23:42:07 +0900
committernsfisis <nsfisis@gmail.com>2026-06-22 23:42:07 +0900
commit5ab5f3b316798c1411ce8e6a7f5b091fda93589c (patch)
treec7669f94f5d9bd9adc07bc1aab3f14cfdec1ae5f /crates/shirabe/src
parentb291e714bc739262140323e08fe2fb9e91e00ee7 (diff)
downloadphp-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.tar.gz
php-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.tar.zst
php-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.zip
test: port previously-ignored Composer tests via __ test hatches
Re-evaluate the reason'd #[ignore] tests under the Phase D criterion: a test is unportable ONLY if the APIs/types needed to WRITE it do not exist. A test that compiles but panics at runtime (todo!() body, a regex the regex crate cannot compile) or fails at runtime (incomplete or incorrect impl behavior) is portable -- it is written in full and marked with a reason-less #[ignore]. About 120 test functions move from reason'd #[ignore] to reason-less #[ignore] (the ported-but-not-yet-passing signal). Impl crates gain only additive __ test hatches (init_command, pool, file_downloader, package handle link setters, artifact/path repository, repository manager, svn); no existing logic changes. Tests whose required APIs genuinely do not exist (mock/reflection harness, ApplicationTester, solve() discarding SolverProblemsException, a script::Event that cannot be passed as an originating event) keep their reason'd #[ignore]. cargo check -p shirabe --tests passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src')
-rw-r--r--crates/shirabe/src/command/init_command.rs25
-rw-r--r--crates/shirabe/src/dependency_resolver/pool.rs6
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs10
-rw-r--r--crates/shirabe/src/package/handle.rs102
-rw-r--r--crates/shirabe/src/repository/artifact_repository.rs9
-rw-r--r--crates/shirabe/src/repository/path_repository.rs26
-rw-r--r--crates/shirabe/src/repository/repository_manager.rs6
-rw-r--r--crates/shirabe/src/util/svn.rs15
8 files changed, 199 insertions, 0 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index 22cd75b..f63014c 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -1075,6 +1075,31 @@ impl InitCommand {
file_put_contents(ignore_file, format!("{}{}\n", contents, vendor).as_bytes());
}
+ /// For testing only: invoke the private `parse_author_string`.
+ pub fn __parse_author_string(&self, author: &str) -> Result<IndexMap<String, Option<String>>> {
+ self.parse_author_string(author)
+ }
+
+ /// For testing only: invoke the crate-private `format_authors`.
+ pub fn __format_authors(&self, author: &str) -> Result<Vec<IndexMap<String, PhpMixed>>> {
+ self.format_authors(author)
+ }
+
+ /// For testing only: invoke the crate-private `get_git_config`.
+ pub fn __get_git_config(&mut self) -> IndexMap<String, String> {
+ self.get_git_config()
+ }
+
+ /// For testing only: invoke the crate-private `has_vendor_ignore`.
+ pub fn __has_vendor_ignore(&self, ignore_file: &str, vendor: &str) -> bool {
+ self.has_vendor_ignore(ignore_file, vendor)
+ }
+
+ /// For testing only: invoke the crate-private `add_vendor_ignore`.
+ pub fn __add_vendor_ignore(&self, ignore_file: &str, vendor: &str) {
+ self.add_vendor_ignore(ignore_file, vendor)
+ }
+
pub(crate) fn is_valid_email(&self, email: &str) -> bool {
shirabe_php_shim::filter_var_email(email)
}
diff --git a/crates/shirabe/src/dependency_resolver/pool.rs b/crates/shirabe/src/dependency_resolver/pool.rs
index b25f348..3ea7835 100644
--- a/crates/shirabe/src/dependency_resolver/pool.rs
+++ b/crates/shirabe/src/dependency_resolver/pool.rs
@@ -379,6 +379,12 @@ impl Pool {
pub fn get_unacceptable_fixed_or_locked_packages(&self) -> &Vec<BasePackageHandle> {
&self.unacceptable_fixed_or_locked_packages
}
+
+ /// For testing only: mirrors PHP `Pool implements \Countable` (`count($pool)`),
+ /// returning how many packages have been loaded into the pool.
+ pub fn __count(&self) -> i64 {
+ self.packages.len() as i64
+ }
}
impl fmt::Display for Pool {
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 702a58f..6b2162a 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -771,6 +771,16 @@ impl FileDownloader {
String::new()
}
+ /// For testing only: invoke the crate-private `get_file_name`.
+ pub fn __get_file_name(&self, package: PackageInterfaceHandle, path: &str) -> String {
+ self.get_file_name(package, path)
+ }
+
+ /// For testing only: invoke the crate-private `process_url`.
+ pub fn __process_url(&self, package: PackageInterfaceHandle, url: &str) -> Result<String> {
+ self.process_url(package, url)
+ }
+
/// Process the download url
pub(crate) fn process_url(&self, package: PackageInterfaceHandle, url: &str) -> Result<String> {
if !shirabe_php_shim::extension_loaded("openssl") && Some(0) == strpos(url, "https:") {
diff --git a/crates/shirabe/src/package/handle.rs b/crates/shirabe/src/package/handle.rs
index 5df4fc0..303983a 100644
--- a/crates/shirabe/src/package/handle.rs
+++ b/crates/shirabe/src/package/handle.rs
@@ -67,6 +67,17 @@ impl AnyPackage {
}
}
+ /// For testing only: reach the base `Package` of a real package variant.
+ /// Crate-private; the public `__set_*` test hatches are built on top of it.
+ pub(crate) fn as_package_mut(&mut self) -> Option<&mut Package> {
+ match self {
+ Self::Package(p) => Some(p),
+ Self::CompletePackage(p) => Some(&mut p.inner),
+ Self::RootPackage(p) => Some(&mut p.inner.inner),
+ _ => None,
+ }
+ }
+
pub fn as_root_package_interface(&self) -> Option<&dyn RootPackageInterface> {
match self {
Self::RootPackage(p) => Some(p),
@@ -1119,6 +1130,97 @@ macro_rules! impl_root_package_interface_handle {
};
}
+macro_rules! impl_real_package_test_setters {
+ ($Handle:ty) => {
+ impl $Handle {
+ /// For testing only: mirrors PHP `Package::setRequires`.
+ pub fn __set_requires(
+ &self,
+ requires: indexmap::IndexMap<String, crate::package::Link>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_requires(requires);
+ }
+
+ /// For testing only: mirrors PHP `Package::setDevRequires`.
+ pub fn __set_dev_requires(
+ &self,
+ dev_requires: indexmap::IndexMap<String, crate::package::Link>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_dev_requires(dev_requires);
+ }
+
+ /// For testing only: mirrors PHP `Package::setConflicts`.
+ pub fn __set_conflicts(
+ &self,
+ conflicts: indexmap::IndexMap<String, crate::package::Link>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_conflicts(conflicts);
+ }
+
+ /// For testing only: mirrors PHP `Package::setProvides`.
+ pub fn __set_provides(
+ &self,
+ provides: indexmap::IndexMap<String, crate::package::Link>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_provides(provides);
+ }
+
+ /// For testing only: mirrors PHP `Package::setReplaces`.
+ pub fn __set_replaces(
+ &self,
+ replaces: indexmap::IndexMap<String, crate::package::Link>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_replaces(replaces);
+ }
+
+ /// For testing only: mirrors PHP `Package::setExtra`.
+ pub fn __set_extra(
+ &self,
+ extra: indexmap::IndexMap<String, shirabe_php_shim::PhpMixed>,
+ ) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_extra(extra);
+ }
+
+ /// For testing only: mirrors PHP `Package::setType`.
+ pub fn __set_type(&self, r#type: String) {
+ self.0
+ .borrow_mut()
+ .as_package_mut()
+ .expect("real package handle invariant")
+ .set_type(r#type);
+ }
+ }
+ };
+}
+
+impl_real_package_test_setters!(PackageHandle);
+impl_real_package_test_setters!(CompletePackageHandle);
+impl_real_package_test_setters!(RootPackageHandle);
+
macro_rules! impl_handle_common {
($Handle:ty) => {
impl $Handle {
diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs
index b913edb..9a28d65 100644
--- a/crates/shirabe/src/repository/artifact_repository.rs
+++ b/crates/shirabe/src/repository/artifact_repository.rs
@@ -65,6 +65,15 @@ impl ArtifactRepository {
format!("artifact repo ({})", self.lookup)
}
+ /// For testing only: drives `initialize` (scanning the lookup directory) and returns the
+ /// packages collected by the inner `ArrayRepository`, mirroring the polymorphic
+ /// `RepositoryInterface::getPackages` dispatch in PHP.
+ pub fn __get_packages(&mut self) -> anyhow::Result<Vec<crate::package::BasePackageHandle>> {
+ self.initialize()?;
+ use crate::repository::RepositoryInterface;
+ self.inner.get_packages()
+ }
+
fn initialize(&mut self) -> anyhow::Result<()> {
self.inner.initialize();
let lookup = self.lookup.clone();
diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs
index 4508460..b8c106a 100644
--- a/crates/shirabe/src/repository/path_repository.rs
+++ b/crates/shirabe/src/repository/path_repository.rs
@@ -113,6 +113,32 @@ impl PathRepository {
)
}
+ /// For testing only: drives `initialize` (globbing the configured url and loading each
+ /// path package) and returns the packages collected by the inner `ArrayRepository`,
+ /// mirroring the polymorphic `RepositoryInterface::getPackages` dispatch in PHP.
+ pub fn __get_packages(&mut self) -> anyhow::Result<Vec<crate::package::BasePackageHandle>> {
+ self.initialize()?;
+ use crate::repository::RepositoryInterface;
+ self.inner.get_packages()
+ }
+
+ /// For testing only: returns `RepositoryInterface::count` after `initialize`.
+ pub fn __count(&mut self) -> anyhow::Result<usize> {
+ self.initialize()?;
+ use crate::repository::RepositoryInterface;
+ self.inner.count()
+ }
+
+ /// For testing only: returns `RepositoryInterface::has_package` after `initialize`.
+ pub fn __has_package(
+ &mut self,
+ package: crate::package::PackageInterfaceHandle,
+ ) -> anyhow::Result<bool> {
+ self.initialize()?;
+ use crate::repository::RepositoryInterface;
+ Ok(self.inner.has_package(package))
+ }
+
pub(crate) fn initialize(&mut self) -> anyhow::Result<()> {
self.inner.initialize();
diff --git a/crates/shirabe/src/repository/repository_manager.rs b/crates/shirabe/src/repository/repository_manager.rs
index 69684e2..403b504 100644
--- a/crates/shirabe/src/repository/repository_manager.rs
+++ b/crates/shirabe/src/repository/repository_manager.rs
@@ -162,6 +162,12 @@ impl RepositoryManager {
&self.repositories
}
+ /// For testing only: exposes the private `repository_classes` map so tests
+ /// can assert on its registered type keys (PHP reads it via ReflectionProperty).
+ pub fn __repository_classes(&self) -> &IndexMap<String, String> {
+ &self.repository_classes
+ }
+
pub fn set_local_repository(&mut self, repository: RepositoryInterfaceHandle) {
self.local_repository = Some(repository);
}
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 319edaf..0a3daf3 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -303,6 +303,21 @@ impl Svn {
args
}
+ /// For testing only: invoke the crate-private `get_command`.
+ pub fn __get_command(
+ &mut self,
+ cmd: Vec<String>,
+ url: &str,
+ path: Option<&str>,
+ ) -> Vec<String> {
+ self.get_command(cmd, url, path)
+ }
+
+ /// For testing only: invoke the crate-private `get_credential_args`.
+ pub fn __get_credential_args(&mut self) -> Vec<String> {
+ self.get_credential_args()
+ }
+
/// Get the password for the svn command. Can be empty.
///
/// @throws \LogicException