Skip to content

Commit c3900aa

Browse files
authored
Revert "Revert "Add integration tests""
1 parent dece967 commit c3900aa

26 files changed

+379
-3
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ closure = []
4141
embed = []
4242

4343
[workspace]
44-
members = ["crates/macros", "crates/cli"]
44+
members = [
45+
"crates/macros",
46+
"crates/cli",
47+
"tests"
48+
]
4549

4650
[package.metadata.docs.rs]
4751
rustdoc-args = ["--cfg", "docs"]

guide/src/types/binary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn test_binary(input: Binary<u32>) -> Binary<u32> {
4545
```php
4646
<?php
4747

48-
$data = pack('*L', [1, 2, 3, 4, 5]);
49-
$output = unpack('*L', test_binary($data));
48+
$data = pack('L*', 1, 2, 3, 4, 5);
49+
$output = unpack('L*', test_binary($data));
5050
var_dump($output); // array(5) { [0] => 5, [1] => 4, [2] => 3, [3] => 2, [4] => 1 }
5151
```

src/closure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class_derives!(Closure);
171171
///
172172
/// This trait is automatically implemented on functions with up to 8
173173
/// parameters.
174+
#[allow(clippy::missing_safety_doc)]
174175
pub unsafe trait PhpClosure {
175176
/// Invokes the closure.
176177
fn invoke<'a>(&'a mut self, parser: ArgParser<'a, '_>, ret: &mut Zval);

tests/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "tests"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
license = "MIT OR Apache-2.0"
7+
8+
[dependencies]
9+
ext-php-rs = { path = "../", features = ["closure"] }
10+
11+
[lib]
12+
crate-type = ["cdylib"]

tests/src/integration/_utils.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
function assert_exception_thrown(callable $callback): void
4+
{
5+
try {
6+
call_user_func($callback);
7+
} catch (\Throwable $th) {
8+
return;
9+
}
10+
throw new Exception("Excption was not thrown", 255);
11+
}

tests/src/integration/array.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
require('_utils.php');
4+
5+
// Tests sequential arrays
6+
$array = test_array(['a', 'b', 'c']);
7+
8+
assert(is_array($array));
9+
assert(count($array) === 3);
10+
assert(in_array('a', $array));
11+
assert(in_array('b', $array));
12+
assert(in_array('c', $array));
13+
14+
// Tests associative arrays
15+
$assoc = test_array_assoc([
16+
'a' => '1',
17+
'b' => '2',
18+
'c' => '3'
19+
]);
20+
21+
assert(array_key_exists('a', $assoc));
22+
assert(array_key_exists('b', $assoc));
23+
assert(array_key_exists('c', $assoc));
24+
assert(in_array('1', $assoc));
25+
assert(in_array('2', $assoc));
26+
assert(in_array('3', $assoc));

tests/src/integration/array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn binary_works() {
3+
assert!(crate::integration::run_php("array.php"));
4+
}

tests/src/integration/binary.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require('_utils.php');
4+
5+
$bin = test_binary(pack('L*', 1, 2, 3, 4, 5));
6+
$result = unpack('L*', $bin);
7+
8+
assert(count($result) === 5);
9+
assert(in_array(1, $result));
10+
assert(in_array(2, $result));
11+
assert(in_array(3, $result));
12+
assert(in_array(4, $result));
13+
assert(in_array(5, $result));

tests/src/integration/binary.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn binary_works() {
3+
assert!(crate::integration::run_php("binary.php"));
4+
}

tests/src/integration/bool.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
require('_utils.php');
4+
5+
assert(test_bool(true) === true);
6+
assert(test_bool(false) === false);

0 commit comments

Comments
 (0)