diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:51:53 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:51:53 +0900 |
| commit | c396d54f0302658304aa924a85b470f02d348182 (patch) | |
| tree | 08d3df986e3fe84c13450c328200b3bef7b6cf5d /crates | |
| parent | 53f027302ebcb91f6fb9b177f5e7e9e2d00c5089 (diff) | |
| download | php-shirabe-c396d54f0302658304aa924a85b470f02d348182.tar.gz php-shirabe-c396d54f0302658304aa924a85b470f02d348182.tar.zst php-shirabe-c396d54f0302658304aa924a85b470f02d348182.zip | |
test: port ForgejoUrl, Silencer, PlatformRequirementFilterFactory tests
Factory's instance-creation tests pass. ForgejoUrl (undelimited regex panic),
Silencer (trigger_error/microtime todo!()), and the factory's unknown-type
case (get_debug_type todo!()) are marked #[ignore].
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
5 files changed, 164 insertions, 0 deletions
diff --git a/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs b/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs index 1199c1c..0991fef 100644 --- a/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs +++ b/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs @@ -1,2 +1,3 @@ mod ignore_all_platform_requirement_filter_test; mod ignore_nothing_platform_requirement_filter_test; +mod platform_requirement_filter_factory_test; diff --git a/crates/shirabe/tests/filter/platform_requirement_filter/platform_requirement_filter_factory_test.rs b/crates/shirabe/tests/filter/platform_requirement_filter/platform_requirement_filter_factory_test.rs index f8230a4..306ce0c 100644 --- a/crates/shirabe/tests/filter/platform_requirement_filter/platform_requirement_filter_factory_test.rs +++ b/crates/shirabe/tests/filter/platform_requirement_filter/platform_requirement_filter_factory_test.rs @@ -1 +1,76 @@ //! ref: composer/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php + +use shirabe::filter::platform_requirement_filter::{ + IgnoreAllPlatformRequirementFilter, IgnoreListPlatformRequirementFilter, + IgnoreNothingPlatformRequirementFilter, PlatformRequirementFilterFactory, +}; +use shirabe_php_shim::PhpMixed; + +#[test] +fn test_from_bool_or_list() { + // 'true creates IgnoreAllFilter' + let filter = PlatformRequirementFilterFactory::from_bool_or_list(PhpMixed::Bool(true)).unwrap(); + assert!( + filter + .as_any() + .downcast_ref::<IgnoreAllPlatformRequirementFilter>() + .is_some() + ); + + // 'false creates IgnoreNothingFilter' + let filter = PlatformRequirementFilterFactory::from_bool_or_list(PhpMixed::Bool(false)).unwrap(); + assert!( + filter + .as_any() + .downcast_ref::<IgnoreNothingPlatformRequirementFilter>() + .is_some() + ); + + // 'list creates IgnoreListFilter' + let filter = PlatformRequirementFilterFactory::from_bool_or_list(PhpMixed::List(vec![ + PhpMixed::String("php".to_string()), + PhpMixed::String("ext-json".to_string()), + ])) + .unwrap(); + assert!( + filter + .as_any() + .downcast_ref::<IgnoreListPlatformRequirementFilter>() + .is_some() + ); +} + +#[test] +#[ignore = "get_debug_type is todo!() in the php-shim (used to build the error message)"] +fn test_from_bool_throws_exception_if_type_is_unknown() { + let result = PlatformRequirementFilterFactory::from_bool_or_list(PhpMixed::Null); + let err = result.unwrap_err(); + assert_eq!( + "PlatformRequirementFilter: Unknown $boolOrList parameter null. Please report at https://github.com/composer/composer/issues/new.", + err.to_string() + ); +} + +#[test] +fn test_ignore_all() { + let platform_requirement_filter = PlatformRequirementFilterFactory::ignore_all(); + + assert!( + platform_requirement_filter + .as_any() + .downcast_ref::<IgnoreAllPlatformRequirementFilter>() + .is_some() + ); +} + +#[test] +fn test_ignore_nothing() { + let platform_requirement_filter = PlatformRequirementFilterFactory::ignore_nothing(); + + assert!( + platform_requirement_filter + .as_any() + .downcast_ref::<IgnoreNothingPlatformRequirementFilter>() + .is_some() + ); +} diff --git a/crates/shirabe/tests/util/forgejo_url_test.rs b/crates/shirabe/tests/util/forgejo_url_test.rs index 970578e..17dae04 100644 --- a/crates/shirabe/tests/util/forgejo_url_test.rs +++ b/crates/shirabe/tests/util/forgejo_url_test.rs @@ -1 +1,43 @@ //! ref: composer/tests/Composer/Test/Util/ForgejoUrlTest.php + +use shirabe::util::forgejo_url::ForgejoUrl; + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_create() { + for repo_url in create_provider() { + let forgejo_url = ForgejoUrl::try_from(Some(repo_url)); + + assert!(forgejo_url.is_some()); + let forgejo_url = forgejo_url.unwrap(); + assert_eq!("codeberg.org", forgejo_url.origin_url); + assert_eq!("acme", forgejo_url.owner); + assert_eq!("repo", forgejo_url.repository); + assert_eq!( + "https://codeberg.org/api/v1/repos/acme/repo", + forgejo_url.api_url + ); + } +} + +fn create_provider() -> Vec<&'static str> { + vec![ + "git@codeberg.org:acme/repo.git", + "https://codeberg.org/acme/repo", + "https://codeberg.org/acme/repo.git", + ] +} + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_create_invalid() { + assert!(ForgejoUrl::create("https://example.org").is_err()); +} + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_generate_ssh_url() { + let forgejo_url = ForgejoUrl::create("git@codeberg.org:acme/repo.git").unwrap(); + + assert_eq!("git@codeberg.org:acme/repo.git", forgejo_url.generate_ssh_url()); +} diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index 1ce0dd7..349aeb6 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -1 +1,3 @@ +mod forgejo_url_test; mod platform_test; +mod silencer_test; diff --git a/crates/shirabe/tests/util/silencer_test.rs b/crates/shirabe/tests/util/silencer_test.rs index 8152b6e..42d0be4 100644 --- a/crates/shirabe/tests/util/silencer_test.rs +++ b/crates/shirabe/tests/util/silencer_test.rs @@ -1 +1,45 @@ //! ref: composer/tests/Composer/Test/Util/SilencerTest.php + +use shirabe::util::silencer::Silencer; +use shirabe_php_shim::{E_USER_WARNING, RuntimeException, error_reporting, microtime, trigger_error}; + +/// Test succeeds when no warnings are emitted externally, and original level is restored. +#[test] +#[ignore = "trigger_error is todo!() in the php-shim"] +fn test_silencer() { + let before = error_reporting(None); + + // Check warnings are suppressed correctly + Silencer::suppress(None); + trigger_error("Test", E_USER_WARNING); + Silencer::restore(); + + // Check all parameters and return values are passed correctly in a silenced call. + let result = Silencer::call(|| { + trigger_error("Test", E_USER_WARNING); + + let (a, b, c) = (2, 3, 4); + Ok(a * b * c) + }) + .unwrap(); + assert_eq!(24, result); + + // Check the error reporting setting was restored correctly + assert_eq!(before, error_reporting(None)); +} + +/// Test whether exception from silent callbacks are correctly forwarded. +#[test] +#[ignore = "microtime is todo!() in the php-shim"] +fn test_silenced_exception() { + let verification = format!("{}", microtime(false)); + let err = Silencer::call(|| -> anyhow::Result<()> { + Err(RuntimeException { + message: verification.clone(), + code: 0, + } + .into()) + }) + .unwrap_err(); + assert_eq!(verification, err.to_string()); +} |
