//! ref: composer/tests/Composer/Test/Installer/BinaryInstallerTest.php use crate::test_case::get_package; use base64::Engine; use shirabe::installer::BinaryInstaller; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::util::Filesystem; use shirabe::util::ProcessExecutor; use std::cell::RefCell; use std::fs; use std::rc::Rc; use tempfile::TempDir; /// Mirror of setUp(): builds temp root/vendor/bin dirs plus a mocked IO. PHP uses a /// PHPUnit IOInterface mock with no expectations; a NullIO is the closest analogue. struct SetUp { root: TempDir, vendor_dir: String, bin_dir: String, io: Rc>, fs: Filesystem, } fn set_up() -> SetUp { let fs = Filesystem::new(None); let root = TempDir::new().unwrap(); let root_dir = fs::canonicalize(root.path()) .unwrap() .to_string_lossy() .into_owned(); let vendor_dir = format!("{}/vendor", root_dir); fs::create_dir_all(&vendor_dir).unwrap(); let bin_dir = format!("{}/bin", root_dir); fs::create_dir_all(&bin_dir).unwrap(); let io: Rc> = Rc::new(RefCell::new(NullIO::new())); SetUp { root, vendor_dir, bin_dir, io, fs, } } fn tear_down(setup: &mut SetUp) { let root = setup.root.path().to_path_buf(); setup.fs.remove_directory(&root).ok(); } /// ref: BinaryInstallerTest::executableBinaryProvider fn executable_binary_provider() -> Vec<(&'static str, Vec)> { vec![ ( "simple php file", b"