diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 03:45:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 03:45:40 +0900 |
| commit | a7306115bd93694d839df1897f495f18a5dafae6 (patch) | |
| tree | 0220ac3970e310bd4e49c25a269535ffe3052d6b /crates/shirabe/tests/script | |
| parent | 06b5f60fd066ec0e1e41c5f85973b323d429b464 (diff) | |
| download | php-shirabe-a7306115bd93694d839df1897f495f18a5dafae6.tar.gz php-shirabe-a7306115bd93694d839df1897f495f18a5dafae6.tar.zst php-shirabe-a7306115bd93694d839df1897f495f18a5dafae6.zip | |
test(script): port Script EventTest
Both cases ignored: calculate_originating_event is todo!(), and the nested
case cannot be expressed since set_originating_event takes a concrete
event_dispatcher::Event. setUp/tearDown not ported.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/script')
| -rw-r--r-- | crates/shirabe/tests/script/event_test.rs | 63 | ||||
| -rw-r--r-- | crates/shirabe/tests/script/main.rs | 1 |
2 files changed, 64 insertions, 0 deletions
diff --git a/crates/shirabe/tests/script/event_test.rs b/crates/shirabe/tests/script/event_test.rs index 47891c7..424f553 100644 --- a/crates/shirabe/tests/script/event_test.rs +++ b/crates/shirabe/tests/script/event_test.rs @@ -1 +1,64 @@ //! ref: composer/tests/Composer/Test/Script/EventTest.php + +use std::cell::RefCell; +use std::rc::Rc; + +use indexmap::IndexMap; +use shirabe::composer::{ComposerHandle, PartialOrFullComposer}; +use shirabe::config::Config; +use shirabe::event_dispatcher::Event as BaseEvent; +use shirabe::io::IOInterface; +use shirabe::io::null_io::NullIO; +use shirabe::package::{RootPackageHandle, RootPackageInterfaceHandle}; +use shirabe::script::Event; + +fn create_composer_instance() -> ComposerHandle { + let composer = + ComposerHandle::from_rc_unchecked(Rc::new(RefCell::new(PartialOrFullComposer::new_full()))); + let config = Rc::new(RefCell::new(Config::new(true, None))); + composer.borrow_mut().set_config(config); + let package: RootPackageInterfaceHandle = + RootPackageHandle::new("foo".to_string(), "1.0.0.0".to_string(), "1.0.0".to_string()) + .into(); + composer.borrow_mut().set_package(package); + composer +} + +#[test] +#[ignore = "Event::calculate_originating_event (called by set_originating_event) is todo!()"] +fn test_event_sets_originating_event() { + let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new())); + let composer = create_composer_instance(); + + let originating_event = + BaseEvent::new("originatingEvent".to_string(), vec![], IndexMap::new()); + + let mut script_event = Event::new( + "test".to_string(), + composer.downgrade(), + io, + true, + vec![], + IndexMap::new(), + ); + + assert!( + script_event.get_originating_event().is_none(), + "originatingEvent is initialized as null" + ); + + script_event.set_originating_event(originating_event); + + assert!(script_event.get_originating_event().is_some()); +} + +// In PHP, the intermediate originating event is itself a Script\Event, and +// getOriginatingEvent() recurses to return the upper-most event. Here +// set_originating_event takes a concrete event_dispatcher::Event, so a Script +// Event cannot be passed as the originating event (it is not polymorphic), and +// the test cannot be expressed faithfully. +#[test] +#[ignore = "set_originating_event takes a concrete event_dispatcher::Event; a Script Event cannot be passed as originating event, and calculate_originating_event is todo!()"] +fn test_event_calculates_nested_originating_event() { + todo!() +} diff --git a/crates/shirabe/tests/script/main.rs b/crates/shirabe/tests/script/main.rs new file mode 100644 index 0000000..83ac806 --- /dev/null +++ b/crates/shirabe/tests/script/main.rs @@ -0,0 +1 @@ +mod event_test; |
