Skip to content

Commit de94e49

Browse files
committed
Modify test_php_scripts_with_condition.
1 parent 52770c3 commit de94e49

File tree

8 files changed

+95
-75
lines changed

8 files changed

+95
-75
lines changed

examples/hello/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ fn throw_exception(_: &mut [Val]) -> phper::Result<()> {
2424

2525
#[php_get_module]
2626
pub fn get_module() -> Module {
27-
let mut module = Module::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"));
27+
let mut module = Module::new(
28+
env!("CARGO_PKG_NAME"),
29+
env!("CARGO_PKG_VERSION"),
30+
env!("CARGO_PKG_AUTHORS"),
31+
);
2832

2933
// register module ini
3034
module.add_bool_ini("hello.enable", false, Policy::All);

examples/hello/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{env, path::Path};
55
fn test_php() {
66
test_php_scripts(
77
env!("CARGO_BIN_EXE_hello"),
8-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
8+
&[&Path::new(env!("CARGO_MANIFEST_DIR"))
99
.join("tests")
1010
.join("php")
1111
.join("test.php")],

examples/log/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use phper::{
55

66
#[php_get_module]
77
pub fn get_module() -> Module {
8-
let mut module = Module::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"));
8+
let mut module = Module::new(
9+
env!("CARGO_PKG_NAME"),
10+
env!("CARGO_PKG_VERSION"),
11+
env!("CARGO_PKG_AUTHORS"),
12+
);
913

1014
module.add_function(
1115
"log_say",

examples/log/tests/integration.rs

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,64 @@ use std::{env, path::Path, str};
55
fn test_php() {
66
test_php_scripts_with_condition(
77
env!("CARGO_BIN_EXE_log"),
8-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
9-
.join("tests")
10-
.join("php")
11-
.join("test_php_say.php")],
12-
|output| {
13-
let stdout = str::from_utf8(&output.stdout).unwrap();
14-
stdout == "Hello, world!" && output.status.success()
15-
},
16-
);
17-
18-
test_php_scripts_with_condition(
19-
env!("CARGO_BIN_EXE_log"),
20-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
21-
.join("tests")
22-
.join("php")
23-
.join("test_php_notice.php")],
24-
|output| {
25-
let stdout = str::from_utf8(&output.stdout).unwrap();
26-
stdout.contains("Notice:")
27-
&& stdout.contains("Something happened: just for test")
28-
&& output.status.success()
29-
},
30-
);
31-
32-
test_php_scripts_with_condition(
33-
env!("CARGO_BIN_EXE_log"),
34-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
35-
.join("tests")
36-
.join("php")
37-
.join("test_php_warning.php")],
38-
|output| {
39-
let stdout = str::from_utf8(&output.stdout).unwrap();
40-
stdout.contains("Warning:")
41-
&& stdout.contains("Something warning: just for test")
42-
&& output.status.success()
43-
},
44-
);
45-
46-
test_php_scripts_with_condition(
47-
env!("CARGO_BIN_EXE_log"),
48-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
49-
.join("tests")
50-
.join("php")
51-
.join("test_php_error.php")],
52-
|output| {
53-
let stdout = str::from_utf8(&output.stdout).unwrap();
54-
stdout.contains("Fatal error:")
55-
&& stdout.contains("Something gone failed: just for test")
56-
},
57-
);
58-
59-
test_php_scripts_with_condition(
60-
env!("CARGO_BIN_EXE_log"),
61-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
62-
.join("tests")
63-
.join("php")
64-
.join("test_php_deprecated.php")],
65-
|output| {
66-
let stdout = str::from_utf8(&output.stdout).unwrap();
67-
stdout.contains("Deprecated:")
68-
&& stdout.contains("Something deprecated: just for test")
69-
&& output.status.success()
70-
},
8+
&[
9+
(
10+
&Path::new(env!("CARGO_MANIFEST_DIR"))
11+
.join("tests")
12+
.join("php")
13+
.join("test_php_say.php"),
14+
&|output| {
15+
let stdout = str::from_utf8(&output.stdout).unwrap();
16+
stdout == "Hello, world!" && output.status.success()
17+
},
18+
),
19+
(
20+
&Path::new(env!("CARGO_MANIFEST_DIR"))
21+
.join("tests")
22+
.join("php")
23+
.join("test_php_notice.php"),
24+
&|output| {
25+
let stdout = str::from_utf8(&output.stdout).unwrap();
26+
stdout.contains("Notice:")
27+
&& stdout.contains("Something happened: just for test")
28+
&& output.status.success()
29+
},
30+
),
31+
(
32+
&Path::new(env!("CARGO_MANIFEST_DIR"))
33+
.join("tests")
34+
.join("php")
35+
.join("test_php_warning.php"),
36+
&|output| {
37+
let stdout = str::from_utf8(&output.stdout).unwrap();
38+
stdout.contains("Warning:")
39+
&& stdout.contains("Something warning: just for test")
40+
&& output.status.success()
41+
},
42+
),
43+
(
44+
&Path::new(env!("CARGO_MANIFEST_DIR"))
45+
.join("tests")
46+
.join("php")
47+
.join("test_php_error.php"),
48+
&|output| {
49+
let stdout = str::from_utf8(&output.stdout).unwrap();
50+
stdout.contains("Fatal error:")
51+
&& stdout.contains("Something gone failed: just for test")
52+
},
53+
),
54+
(
55+
&Path::new(env!("CARGO_MANIFEST_DIR"))
56+
.join("tests")
57+
.join("php")
58+
.join("test_php_deprecated.php"),
59+
&|output| {
60+
let stdout = str::from_utf8(&output.stdout).unwrap();
61+
stdout.contains("Deprecated:")
62+
&& stdout.contains("Something deprecated: just for test")
63+
&& output.status.success()
64+
},
65+
),
66+
],
7167
);
7268
}

phper-test/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ use std::{
1010
};
1111
use tempfile::NamedTempFile;
1212

13-
pub fn test_php_scripts(exe_path: impl AsRef<Path>, scripts: &[impl AsRef<Path>]) {
14-
test_php_scripts_with_condition(exe_path, scripts, |output| output.status.success());
13+
pub fn test_php_scripts(exe_path: impl AsRef<Path>, scripts: &[&dyn AsRef<Path>]) {
14+
let condition = |output: Output| output.status.success();
15+
let scripts = scripts
16+
.into_iter()
17+
.map(|s| (*s, &condition as _))
18+
.collect::<Vec<_>>();
19+
test_php_scripts_with_condition(exe_path, &*scripts);
1520
}
1621

1722
pub fn test_php_scripts_with_condition(
1823
exe_path: impl AsRef<Path>,
19-
scripts: &[impl AsRef<Path>],
20-
condition: impl Fn(Output) -> bool,
24+
scripts: &[(&dyn AsRef<Path>, &dyn Fn(Output) -> bool)],
2125
) {
2226
let context = php_context();
2327

@@ -33,7 +37,7 @@ pub fn test_php_scripts_with_condition(
3337
.write_fmt(format_args!("extension={}\n", lib_path.to_str().unwrap()))
3438
.unwrap();
3539

36-
for script in scripts {
40+
for (script, condition) in scripts {
3741
let script = script.as_ref();
3842
let mut cmd = Command::new(&context.php_bin);
3943
let args = &[

phper/src/arrays.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ impl Array {
3131
pub fn insert(&mut self, key: impl AsRef<str>, value: &mut Val) {
3232
let key = key.as_ref();
3333
unsafe {
34-
phper_zend_hash_str_update(self.inner, key.as_ptr().cast(), key.len(), value.as_mut_ptr());
34+
phper_zend_hash_str_update(
35+
self.inner,
36+
key.as_ptr().cast(),
37+
key.len(),
38+
value.as_mut_ptr(),
39+
);
3540
}
3641
}
3742

phper/src/modules.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ use std::{
1515
mem::{size_of, zeroed},
1616
os::raw::{c_int, c_uchar, c_uint, c_ushort},
1717
ptr::{null, null_mut},
18-
sync::RwLock,
18+
sync::{
19+
atomic::{AtomicPtr, Ordering},
20+
RwLock,
21+
},
1922
};
20-
use std::sync::atomic::{AtomicPtr, Ordering};
2123

2224
static GLOBAL_MODULE: AtomicPtr<Module> = AtomicPtr::new(null_mut());
2325

phper/src/values.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ impl SetVal for Array {
197197
unsafe {
198198
let mut new_val = Val::empty();
199199
phper_zval_arr(new_val.as_mut_ptr(), self.into_raw());
200-
phper_zval_zval(val.as_mut_ptr(), new_val.as_mut_ptr(), true.into(), false.into());
200+
phper_zval_zval(
201+
val.as_mut_ptr(),
202+
new_val.as_mut_ptr(),
203+
true.into(),
204+
false.into(),
205+
);
201206
}
202207
}
203208
}

0 commit comments

Comments
 (0)