Skip to content

Commit e8976fe

Browse files
committed
improve test
1 parent 553e829 commit e8976fe

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ phper = "0.13.1"
1414

1515
[dev-dependencies]
1616
phper-test = "0.13.1"
17+
tempfile = "3"
18+
19+
[build-dependencies]
20+
phper-build = "0.13.1"
1721

1822
[lib]
1923
crate-type = ["lib", "cdylib"]

tests/integration.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
use phper_test::{cli::test_php_scripts, utils::get_lib_path};
1+
use phper_test::{cli::test_long_term_php_script_with_condition, utils::get_lib_path};
22
use std::{
33
env,
44
path::{Path, PathBuf},
5+
thread::sleep,
6+
time::Duration,
57
};
8+
use std::io::{Write, Read, Seek, SeekFrom};
9+
use tempfile::NamedTempFile;
610

711
#[test]
812
fn test_recommended_watcher() {
9-
test_php_scripts(
13+
let mut tmpfile = NamedTempFile::new().unwrap();
14+
write!(tmpfile, "").unwrap();
15+
16+
test_long_term_php_script_with_condition(
1017
get_lib_path(
1118
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
1219
.join("target"),
1320
"php_ext_fs_notify",
1421
),
15-
&[&Path::new(env!("CARGO_MANIFEST_DIR"))
22+
Path::new(env!("CARGO_MANIFEST_DIR"))
1623
.join("tests")
1724
.join("php")
18-
.join("recommended_watcher.php")],
25+
.join("recommended_watcher.php"),
26+
|_| {
27+
sleep(Duration::from_secs(3));
28+
let mut tmpfile_watch = tmpfile.reopen().unwrap();
29+
write!(tmpfile_watch, "notice").unwrap();
30+
}
1931
);
32+
33+
tmpfile.seek(SeekFrom::Start(0)).unwrap();
34+
35+
let mut buf = String::new();
36+
tmpfile.read_to_string(&mut buf).unwrap();
37+
assert_eq!("notice", buf);
2038
}

tests/php/recommended_watcher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
$watcher->watch(function (FsNotify\Event $event) {
1010
var_dump($event->getKind());
1111
var_dump($event->getPaths());
12+
exit;
1213
});

0 commit comments

Comments
 (0)