Skip to content

Commit d618bf3

Browse files
committed
Write php integration tests.
1 parent 95e0395 commit d618bf3

File tree

12 files changed

+192
-29
lines changed

12 files changed

+192
-29
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11-
# RUST_BACKTRACE: 1
12-
# RUST_LOG: debug
11+
# RUST_BACKTRACE: 1
12+
# RUST_LOG: debug
1313
RUSTFLAGS: "-D warnings"
1414

1515
jobs:
@@ -35,7 +35,7 @@ jobs:
3535
php-version: ${{ matrix.php-version }}
3636
tools: php-config
3737

38-
- name: PHP Config
38+
- name: PHP version
3939
run: php-config --version && php-config --phpapi && php --version
4040

4141
- name: Checkout
@@ -44,20 +44,40 @@ jobs:
4444
- name: Install Rust
4545
uses: actions-rs/toolchain@v1
4646
with:
47-
toolchain: nightly-2020-11-09
48-
override: true
49-
components: rustfmt, clippy
47+
toolchain: nightly-2020-11-09
48+
override: true
49+
components: rustfmt, clippy
5050

51-
- uses: actions-rs/cargo@v1
51+
- name: Install Cargo make
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: install
55+
args: cargo-make
56+
57+
- name: Cargo fmt
58+
uses: actions-rs/cargo@v1
5259
with:
5360
command: fmt
5461
args: --all -- --check
55-
56-
- uses: actions-rs/cargo@v1
62+
63+
- name: Cargo build
64+
uses: actions-rs/cargo@v1
65+
with:
66+
command: build
67+
68+
- name: Cargo test
69+
uses: actions-rs/cargo@v1
5770
with:
5871
command: test
5972
args: -- --nocapture
6073

61-
- uses: actions-rs/cargo@v1
74+
- name: Cargo doc
75+
uses: actions-rs/cargo@v1
6276
with:
6377
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

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/target
22
**/*.rs.bk
33
Cargo.lock
4-
/.idea
5-
.vscode
64
/.cargo
75
/vendor
8-
/trail-extension
9-
*.test.sh

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"phper-build",
66
"phper-macros",
77
"phper-sys",
8+
"phper-test",
89

910
# internal
1011
"examples/simple",

examples/simple/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ crate-type = ["cdylib"]
1313
[dependencies]
1414
phper = { version = "0.2", path = "../../phper" }
1515

16+
[dev-dependencies]
17+
phper-test = { version = "0.2", path = "../../phper-test" }
18+
1619
[build-dependencies]
1720
phper-build = { version = "0.2", path = "../../phper-build" }

examples/simple/Makefile.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ TARGET_DIR = "${CARGO_MAKE_WORKING_DIRECTORY}/../../target"
44

55
[env.development]
66
TARGET_BUILD_DIR = "${TARGET_DIR}/debug"
7+
BUILD_ARGS = ""
8+
TEST_ARGS = ""
79

810
[env.production]
911
TARGET_BUILD_DIR = "${TARGET_DIR}/release"
12+
BUILD_ARGS = "--release"
13+
TEST_ARGS = "--release"
14+
15+
[tasks.build]
16+
command = "cargo"
17+
args = ["build", "${BUILD_ARGS}"]
18+
19+
[tasks.test]
20+
command = "cargo"
21+
args = ["test", "${TEST_ARGS}", "--", "--nocapture"]
22+
env = { "LIB_SO" = "${TARGET_BUILD_DIR}/lib${CARGO_MAKE_CRATE_NAME}.so" }
1023

1124
[tasks.install]
1225
dependencies = ["build"]
@@ -16,15 +29,3 @@ script = [
1629
echo Installing shared extensions: `${PHP_CONFIG} --extension-dir`
1730
"""
1831
]
19-
20-
[tasks.test-php]
21-
script = [
22-
"`${PHP_CONFIG} --php-binary` tests/confirm_compiled.php"
23-
]
24-
25-
[tasks.test-all]
26-
dependencies = [
27-
"install",
28-
"test",
29-
"test-php",
30-
]

examples/simple/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ pub fn my_class_foo(execute_data: ExecuteData) -> impl SetVal {
129129
let foo = unsafe {
130130
zend_read_property(MY_CLASS_CE.get(), this, c_str_ptr!("foo"), 3, 1, null_mut())
131131
};
132-
let foo = Val::from_raw(foo);
133-
let foo = foo.as_c_str().unwrap().to_str().unwrap();
134-
format!("{}{}", prefix, foo)
132+
// let foo = Val::from_raw(foo);
133+
// let foo = foo.as_c_str().unwrap().to_str().unwrap();
134+
// format!("{}{}", prefix, foo)
135+
136+
""
135137
})
136138
}
137139

examples/simple/tests/integration.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use phper_test::test_php_scripts;
2+
use std::{env, ffi::OsStr, fmt::Debug, path::Path, process::Command, sync::Once};
3+
4+
#[test]
5+
fn test_php() {
6+
test_php_scripts(
7+
Path::new(env!("CARGO_MANIFEST_DIR"))
8+
.join("..")
9+
.join("..")
10+
.join("target"),
11+
env!("CARGO_PKG_NAME"),
12+
&[Path::new(env!("CARGO_MANIFEST_DIR"))
13+
.join("tests")
14+
.join("php")
15+
.join("test.php")],
16+
);
17+
}

phper-test/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "phper-test"
3+
version = "0.2.0"
4+
authors = ["jmjoy <[email protected]>"]
5+
edition = "2018"
6+
description = "PHPer testing utilities."
7+
repository = "https://github.com/jmjoy/phper.git"
8+
license = "Unlicense"
9+
keywords = ["php", "binding"]
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
13+
[dependencies]
14+
once_cell = "1.5.2"
15+
serde_json = "1.0.59"
16+
tempfile = "3.1.0"

phper-test/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

0 commit comments

Comments
 (0)