Skip to content

Commit 44a9f5a

Browse files
committed
Pass the tests/integration tests.
1 parent 28fa2fa commit 44a9f5a

File tree

9 files changed

+76
-31
lines changed

9 files changed

+76
-31
lines changed

examples/hello/tests/integration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
99
// See the Mulan PSL v2 for more details.
1010

11-
use phper_test::{cli::{test_php_scripts, test_php_scripts_with_lib}, utils::get_lib_path_by_example};
11+
use phper_test::{
12+
cli::{test_php_scripts, test_php_scripts_with_lib},
13+
utils::get_lib_path_by_example,
14+
};
1215
use std::{env, path::Path};
1316

1417
#[test]

examples/http-client/tests/integration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
99
// See the Mulan PSL v2 for more details.
1010

11-
use phper_test::{cli::{test_php_scripts, test_php_scripts_with_lib}, utils::get_lib_path_by_example};
11+
use phper_test::{
12+
cli::{test_php_scripts, test_php_scripts_with_lib},
13+
utils::get_lib_path_by_example,
14+
};
1215
use std::{env, path::Path};
1316

1417
#[test]

examples/http-server/tests/integration.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
// See the Mulan PSL v2 for more details.
1010

1111
use hyper::header::CONTENT_TYPE;
12-
use phper_test::{cli::{test_long_term_php_script_with_condition, test_long_term_php_script_with_condition_and_lib}, utils::get_lib_path_by_example};
12+
use phper_test::{
13+
cli::{
14+
test_long_term_php_script_with_condition, test_long_term_php_script_with_condition_and_lib,
15+
},
16+
utils::get_lib_path_by_example,
17+
};
1318
use reqwest::Client;
1419
use std::{env, path::Path, thread::sleep, time::Duration};
1520
use tokio::runtime;
1621

1722
#[test]
1823
fn test_php() {
1924
test_long_term_php_script_with_condition_and_lib(
20-
get_lib_path_by_example(env!("CARGO_BIN_EXE_http-server")),
25+
get_lib_path_by_example(env!("CARGO_BIN_EXE_http-server")),
2126
Path::new(env!("CARGO_MANIFEST_DIR"))
2227
.join("tests")
2328
.join("php")

examples/logging/tests/integration.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
99
// See the Mulan PSL v2 for more details.
1010

11-
use phper_test::{cli::{test_php_scripts_with_condition, test_php_scripts_with_condition_and_lib}, utils::get_lib_path_by_example};
11+
use phper_test::{
12+
cli::{test_php_scripts_with_condition, test_php_scripts_with_condition_and_lib},
13+
utils::get_lib_path_by_example,
14+
};
1215
use std::{env, path::Path, str};
1316

1417
#[test]
@@ -18,7 +21,7 @@ fn test_php() {
1821
.join("php");
1922

2023
test_php_scripts_with_condition_and_lib(
21-
get_lib_path_by_example(env!("CARGO_BIN_EXE_logging")),
24+
get_lib_path_by_example(env!("CARGO_BIN_EXE_logging")),
2225
&[
2326
(&base_dir.join("test_php_say.php"), &|output| {
2427
let stdout = str::from_utf8(&output.stdout).unwrap();

phper-test/src/context.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,27 @@ impl Context {
9999
#[cfg(feature = "fpm")]
100100
#[cfg_attr(docsrs, doc(cfg(feature = "fpm")))]
101101
pub fn find_php_fpm(&self) -> Option<String> {
102-
Path::new(&self.php_bin)
103-
.parent()
104-
.and_then(Path::parent)
105-
.and_then(|p| {
106-
let mut p = p.to_path_buf();
107-
p.push("sbin");
108-
p.push("php-fpm");
109-
p.as_path().to_str().map(|s| s.to_string())
110-
})
102+
use std::ffi::OsStr;
103+
104+
let php_bin = Path::new(&self.php_bin);
105+
php_bin.parent().and_then(Path::parent).and_then(|p| {
106+
php_bin
107+
.file_name()
108+
.and_then(OsStr::to_str)
109+
.and_then(|name| {
110+
let mut p = p.to_path_buf();
111+
p.push("sbin");
112+
p.push(&format!(
113+
"php-fpm{}",
114+
if name.starts_with("php") {
115+
name.chars().skip(3).collect::<String>()
116+
} else {
117+
"".to_owned()
118+
}
119+
));
120+
p.as_path().to_str().map(ToOwned::to_owned)
121+
})
122+
})
111123
}
112124

113125
#[cfg(feature = "fpm")]

phper/src/functions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ pub(crate) const fn create_zend_arg_info(
411411
/// # Examples
412412
///
413413
/// ```
414-
/// use phper::{arrays::Array, functions::call, values::Val};
414+
/// use phper::{arrays::ZArray, functions::call, values::ZVal};
415415
///
416416
/// fn json_encode() -> phper::Result<()> {
417-
/// let mut arr = Array::new();
418-
/// arr.insert("a", Val::new(1));
419-
/// arr.insert("b", Val::new(2));
420-
/// let ret = call("json_encode", &mut [Val::new(arr)])?;
421-
/// assert_eq!(ret.as_string()?, r#"{"a":1,"b":2}"#);
417+
/// let mut arr = ZArray::new();
418+
/// arr.insert("a", ZVal::from(1));
419+
/// arr.insert("b", ZVal::from(2));
420+
/// let ret = call("json_encode", &mut [ZVal::from(arr)])?;
421+
/// assert_eq!(ret.expect_z_str()?.to_str(), Ok(r#"{"a":1,"b":2}"#));
422422
/// Ok(())
423423
/// }
424424
/// ```

phper/src/objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ZObj {
141141
/// # Examples
142142
///
143143
/// ```
144-
/// use phper::{alloc::EBox, classes::StatelessClassEntry, values::Val};
144+
/// use phper::{alloc::EBox, classes::ClassEntry, values::ZVal};
145145
///
146146
/// fn example() -> phper::Result<EBox<Val>> {
147147
/// let mut memcached = StatelessClassEntry::from_globals("Memcached")?.new_object(&mut [])?;

tests/integration/src/values.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use phper::{
1212
alloc::{ebox, EBox},
13-
arrays::ZArray,
13+
arrays::{InsertKey, ZArray},
1414
modules::Module,
1515
objects::ZObject,
1616
values::ZVal,
@@ -61,6 +61,11 @@ fn integrate_returns(module: &mut Module) {
6161
integration_values_return_array,
6262
vec![],
6363
);
64+
module.add_function(
65+
"integration_values_return_kv_array",
66+
integration_values_return_kv_array,
67+
vec![],
68+
);
6469
module.add_function(
6570
"integration_values_return_object",
6671
integration_values_return_object,
@@ -76,6 +81,11 @@ fn integrate_returns(module: &mut Module) {
7681
integration_values_return_option_i64_none,
7782
vec![],
7883
);
84+
module.add_function(
85+
"integration_values_return_ebox_i64",
86+
integration_values_return_ebox_i64,
87+
vec![],
88+
);
7989
module.add_function(
8090
"integration_values_return_result_string_ok",
8191
integration_values_return_result_string_ok,
@@ -119,11 +129,19 @@ fn integration_values_return_string(_: &mut [ZVal]) -> String {
119129
"foo".to_string()
120130
}
121131

122-
fn integration_values_return_array(_: &mut [ZVal]) -> EBox<ZArray> {
132+
fn integration_values_return_array(_: &mut [ZVal]) -> ZArray {
133+
let mut arr = ZArray::new();
134+
arr.insert(InsertKey::NextIndex, ZVal::from("a"));
135+
arr.insert(InsertKey::NextIndex, ZVal::from("b"));
136+
arr.insert(InsertKey::NextIndex, ZVal::from("c"));
137+
arr
138+
}
139+
140+
fn integration_values_return_kv_array(_: &mut [ZVal]) -> ZArray {
123141
let mut arr = ZArray::new();
124142
arr.insert("a", ZVal::from(1));
125143
arr.insert("b", ZVal::from("foo"));
126-
ebox!(arr)
144+
arr
127145
}
128146

129147
fn integration_values_return_object(_: &mut [ZVal]) -> ZObject {
@@ -140,6 +158,10 @@ fn integration_values_return_option_i64_none(_: &mut [ZVal]) -> Option<i64> {
140158
None
141159
}
142160

161+
fn integration_values_return_ebox_i64(_: &mut [ZVal]) -> EBox<i64> {
162+
ebox!(64)
163+
}
164+
143165
fn integration_values_return_result_string_ok(_: &mut [ZVal]) -> phper::Result<String> {
144166
Ok("foo".to_string())
145167
}

tests/integration/tests/php/values.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020
assert_eq(integration_values_return_f64(), 64.0);
2121
assert_eq(integration_values_return_str(), "foo");
2222
assert_eq(integration_values_return_string(), "foo");
23-
assert_eq(integration_values_return_i64_vec(), [0, 1, 2]);
24-
assert_eq(integration_values_return_string_vec(), ["a", "b", "c"]);
25-
assert_eq(array_ksort(integration_values_return_i64_map()), ["a" => 0, "b" => 1, "c" => 2]);
26-
assert_eq(array_ksort(integration_values_return_string_map()), ["a" => "x", "b" => "y", "c" => "z"]);
27-
assert_eq(integration_values_return_i64_index_map(), ["a" => 0, "b" => 1, "c" => 2]);
28-
assert_eq(integration_values_return_array(), ["a" => 1, "b" => "foo"]);
23+
assert_eq(integration_values_return_array(), ["a", "b", "c"]);
24+
assert_eq(integration_values_return_kv_array(), ["a" => 1, "b" => "foo"]);
2925
assert_object(integration_values_return_object(), "stdClass", ["foo" => "bar"]);
3026
assert_eq(integration_values_return_option_i64_some(), 64);
3127
assert_eq(integration_values_return_option_i64_none(), null);
28+
assert_eq(integration_values_return_ebox_i64(), 64);
3229
assert_eq(integration_values_return_result_string_ok(), "foo");
3330
assert_throw("integration_values_return_result_string_err", "ErrorException", 0, "a zhe");
3431
assert_eq(integration_values_return_val(), "foo");

0 commit comments

Comments
 (0)