Skip to content

Commit a4c61df

Browse files
feat: integration tests
1 parent 08de883 commit a4c61df

19 files changed

+346
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ closure = []
3030
[workspace]
3131
members = [
3232
"crates/macros",
33-
"crates/cli"
33+
"crates/cli",
34+
"tests"
3435
]
3536

3637
[package.metadata.docs.rs]

guide/src/types/binary.md

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

46-
$data = pack('*L', [1, 2, 3, 4, 5]);
47-
$output = unpack('*L', test_binary($data));
46+
$data = pack('L*', 1, 2, 3, 4, 5);
47+
$output = unpack('L*', test_binary($data));
4848
var_dump($output); // array(5) { [0] => 5, [1] => 4, [2] => 3, [3] => 2, [4] => 1 }
4949
```

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/integration/array.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo implode(' ', test_array(['a', 'b', 'c']));

tests/integration/array_assoc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$output = '';
4+
5+
foreach (test_array_assoc([
6+
'first' => '1',
7+
'second' => '2',
8+
'third' => '3'
9+
]) as $key => $value) {
10+
$output .= "{$key}={$value} ";
11+
}
12+
13+
echo trim($output);

tests/integration/binary.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
4+
$bin = test_binary(pack('L*', 1, 2, 3, 4, 5));
5+
6+
echo implode(' ', unpack('L*', $bin));

tests/integration/bool.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
if (test_bool(true) === true) {
4+
echo 'true ';
5+
}
6+
7+
if (test_bool(false) === false) {
8+
echo 'false';
9+
}

tests/integration/callable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo test_callable(fn($a) => $a, 'callable works');

tests/integration/class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$class = test_class("class", "works");
4+
5+
echo $class->test();

tests/integration/closure.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo test_closure()('closure works');

0 commit comments

Comments
 (0)