Skip to content

Commit cb2afe9

Browse files
committed
Add tests
1 parent da9d1c0 commit cb2afe9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/src/integration/types.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
require('_utils.php');
4+
5+
const TYPES = [
6+
'test_str' => [['string'], 'string'],
7+
'test_string' => [['string'], 'string'],
8+
'test_bool' => [['bool'], 'bool'],
9+
'test_number_signed' => [['int'], 'int'],
10+
'test_number_unsigned' => [['int'], 'int'],
11+
'test_number_float' => [['float'], 'float'],
12+
'test_array' => [['array'], 'array'],
13+
'test_array' => [['array'], 'array'],
14+
'test_array_assoc' => [['array'], 'array'],
15+
'test_binary' => [['string'], 'string'],
16+
'test_nullable' => [['?string'], '?string'],
17+
'test_object' => [['object'], 'object'],
18+
'test_closure' => [[], 'RustClosure'],
19+
'test_closure_once' => [['string'], 'RustClosure'],
20+
'test_callable' => [['callable', 'string'], 'mixed']
21+
];
22+
23+
function toStr(ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null $v): string {
24+
if ($v === null) {
25+
return '<null>';
26+
}
27+
return match (true) {
28+
$v instanceof ReflectionNamedType => $v->allowsNull() ? '?'.$v->getName() : $v->getName(),
29+
$v instanceof ReflectionUnionType => $v->getName(),
30+
$v instanceof ReflectionIntersectionType => $v->getName(),
31+
};
32+
}
33+
34+
foreach (TYPES as $func => [$args, $return]) {
35+
$f = new ReflectionFunction($func);
36+
assert(toStr($f->getReturnType()) === $return, "Wrong return type of $func, expected $return, got ".((string)$f->getReturnType()));
37+
foreach ($f->getParameters() as $idx => $param) {
38+
assert(toStr($param->getType()) === $args[$idx], "Wrong arg type $idx of $func, expected {$args[$idx]}, got ".((string)$param->getType()));
39+
}
40+
}

tests/src/integration/types.rs

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

0 commit comments

Comments
 (0)