diff options
Diffstat (limited to 'crates/shirabe/src/package/version')
| -rw-r--r-- | crates/shirabe/src/package/version/version_guesser.rs | 27 | ||||
| -rw-r--r-- | crates/shirabe/src/package/version/version_selector.rs | 6 |
2 files changed, 30 insertions, 3 deletions
diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index c5bf4c2..6642201 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -20,6 +20,19 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; +/// Seam over the parts of [`VersionGuesser`] that consumers depend on, so they can be exercised +/// with a test double. PHP has no such interface; this exists only to allow mocking the concrete +/// `VersionGuesser` (a Phase C seam). +pub trait VersionGuesserInterface: std::fmt::Debug { + fn guess_version( + &mut self, + package_config: &IndexMap<String, PhpMixed>, + path: &str, + ) -> Result<Option<VersionData>>; + + fn get_root_version_from_env(&self) -> Result<String>; +} + /// Try to guess the current version number based on different VCS configuration. /// /// @phpstan-type Version array{version: string, commit: string|null, pretty_version: string|null}|array{version: string, commit: string|null, pretty_version: string|null, feature_version: string|null, feature_pretty_version: string|null} @@ -747,6 +760,20 @@ impl VersionGuesser { } } +impl VersionGuesserInterface for VersionGuesser { + fn guess_version( + &mut self, + package_config: &IndexMap<String, PhpMixed>, + path: &str, + ) -> Result<Option<VersionData>> { + VersionGuesser::guess_version(self, package_config, path) + } + + fn get_root_version_from_env(&self) -> Result<String> { + VersionGuesser::get_root_version_from_env(self) + } +} + #[derive(Debug)] pub struct FeatureVersionResult { pub version: Option<String>, diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs index 793dd4e..8a0d037 100644 --- a/crates/shirabe/src/package/version/version_selector.rs +++ b/crates/shirabe/src/package/version/version_selector.rs @@ -23,18 +23,18 @@ use crate::package::loader::ArrayLoader; use crate::package::version::VersionParser; use crate::repository::PlatformRepository; use crate::repository::RepositoryInterface; -use crate::repository::RepositorySet; +use crate::repository::RepositorySetInterface; #[derive(Debug)] pub struct VersionSelector { - repository_set: std::rc::Rc<std::cell::RefCell<RepositorySet>>, + repository_set: std::rc::Rc<std::cell::RefCell<dyn RepositorySetInterface>>, platform_constraints: IndexMap<String, Vec<AnyConstraint>>, parser: Option<VersionParser>, } impl VersionSelector { pub fn new( - repository_set: std::rc::Rc<std::cell::RefCell<RepositorySet>>, + repository_set: std::rc::Rc<std::cell::RefCell<dyn RepositorySetInterface>>, platform_repo: Option<&mut crate::repository::PlatformRepository>, ) -> anyhow::Result<Self> { let mut platform_constraints: IndexMap<String, Vec<AnyConstraint>> = IndexMap::new(); |
