Skip to content

Commit d299cc1

Browse files
committed
Passing tests.
1 parent d618bf3 commit d299cc1

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,3 @@ jobs:
7575
uses: actions-rs/cargo@v1
7676
with:
7777
command: doc
78-
79-
- name: Cargo test example simple
80-
uses: actions-rs/cargo@v1
81-
with:
82-
command: make
83-
args: test-php --cwd examples/simple --profile production

examples/simple/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static INI_ENTRIES: IniEntries<2> = IniEntries::new([
3535
fn m_init_simple(args: ModuleArgs) -> bool {
3636
args.register_ini_entries(&INI_ENTRIES);
3737
MY_CLASS_CE.init(c_str_ptr!("MyClass"), &MY_CLASS_METHODS);
38-
MY_CLASS_CE.declare_property("foo", 3, ZEND_ACC_PUBLIC);
38+
MY_CLASS_CE.declare_property("foo", "3", ZEND_ACC_PUBLIC);
3939
true
4040
}
4141

@@ -125,15 +125,14 @@ static MY_CLASS_METHODS: FunctionEntries<1> = FunctionEntries::new([zend_functio
125125
pub fn my_class_foo(execute_data: ExecuteData) -> impl SetVal {
126126
execute_data.parse_parameters::<&str>().map(|prefix| {
127127
let this = execute_data.get_this();
128+
assert_ne!(this as *mut _, null_mut());
128129

129130
let foo = unsafe {
130131
zend_read_property(MY_CLASS_CE.get(), this, c_str_ptr!("foo"), 3, 1, null_mut())
131132
};
132-
// let foo = Val::from_raw(foo);
133-
// let foo = foo.as_c_str().unwrap().to_str().unwrap();
134-
// format!("{}{}", prefix, foo)
135-
136-
""
133+
let foo = Val::from_raw(foo);
134+
let foo = foo.as_c_str().unwrap().to_str().unwrap();
135+
format!("{}{}", prefix, foo)
137136
})
138137
}
139138

examples/simple/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use phper_test::test_php_scripts;
2-
use std::{env, ffi::OsStr, fmt::Debug, path::Path, process::Command, sync::Once};
2+
use std::{env, path::Path};
33

44
#[test]
55
fn test_php() {

examples/simple/tests/php/test.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
ini_set("display_startup_errors", "On");
55
error_reporting(E_ALL);
66

7-
var_dump(get_extension_funcs('simple'));
8-
var_dump(test_simple("aaa", "bbb"));
9-
var_dump((new MyClass())->foo("foo-"));
7+
assert_eq(get_extension_funcs('simple'), ["test_simple"]);
8+
assert_eq(test_simple("aaa", "bbb"), "a = aaa, a_len = 3, b = bbb, b_len = 3");
9+
assert_eq((new MyClass())->foo("foo-"), "foo-3");
10+
11+
function assert_eq($left, $right) {
12+
if ($left !== $right) {
13+
throw new Exception("left != right,\n left: {$left},\n right: {$right};");
14+
}
15+
}

phper-test/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ keywords = ["php", "binding"]
1212

1313
[dependencies]
1414
once_cell = "1.5.2"
15-
serde_json = "1.0.59"
1615
tempfile = "3.1.0"

phper-test/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use once_cell::sync::OnceCell;
2-
use serde_json::Value;
32
use std::{
4-
env, ffi::OsStr, fmt::Debug, fs::read_to_string, io, io::Write, path::Path, process::Command,
3+
env, ffi::OsStr, fmt::Debug, fs::read_to_string, io::Write, path::Path, process::Command,
54
};
6-
use tempfile::{tempfile, NamedTempFile};
5+
use tempfile::NamedTempFile;
76

87
pub fn test_php_scripts(
98
target_dir: impl AsRef<Path>,
@@ -12,7 +11,7 @@ pub fn test_php_scripts(
1211
) {
1312
let context = php_context();
1413

15-
let mut lib_path = target_dir
14+
let lib_path = target_dir
1615
.as_ref()
1716
.join(if cfg!(debug_assertions) {
1817
"debug"
@@ -39,19 +38,21 @@ pub fn test_php_scripts(
3938
.arg(out_ini_temp_file.path())
4039
.arg(script);
4140
let output = cmd.output().unwrap();
41+
let path = script.to_str().unwrap();
42+
43+
println!(
44+
"test php file: {}\nstdout: {}\nstderr: {}",
45+
path,
46+
String::from_utf8(output.stdout).unwrap(),
47+
String::from_utf8(output.stderr).unwrap()
48+
);
4249
if !output.status.success() {
43-
eprintln!(
44-
"stdout: {}\nstderr: {}",
45-
String::from_utf8(output.stdout).unwrap(),
46-
String::from_utf8(output.stderr).unwrap()
47-
);
48-
panic!("test php file `{}` failed", script.to_str().unwrap());
50+
panic!("test php file `{}` failed", path);
4951
}
5052
}
5153
}
5254

5355
struct Context {
54-
php_config: String,
5556
php_bin: String,
5657
ini_content: String,
5758
}
@@ -85,7 +86,6 @@ fn php_context() -> &'static Context {
8586
}
8687

8788
Context {
88-
php_config,
8989
php_bin,
9090
ini_content,
9191
}

0 commit comments

Comments
 (0)