Skip to content

Commit e263dc6

Browse files
committed
fix some tests for older php versions
1 parent 26ade87 commit e263dc6

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tests/integration/tests/php/_common.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ function array_ksort($array) {
6666
ksort($array);
6767
return $array;
6868
}
69+
70+
/* @var string $version Basic php version ('7.0', '8.4') */
71+
function php_at_least(string $version) {
72+
return version_compare(PHP_VERSION, $version, '>=');
73+
}

tests/integration/tests/php/typehints.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
assert_eq($value, 'foobar');
2222

2323
$argumentTypehintProvider = [
24-
// <method>, <expected typehint>, <is nullable>, <is required>
24+
// <method>, <expected typehint>, <is nullable>, <is required>, <(optional)min php version>
2525
['testString', 'string', false, true],
2626
['testStringOptional', 'string', false, false],
2727
['testStringNullable', 'string', true, true],
@@ -56,7 +56,7 @@
5656
['testIterableOptional', 'iterable', false, false],
5757
['testIterableNullable', 'iterable', true, true],
5858

59-
['testNull', 'null', true, true],
59+
['testNull', 'null', true, true, '8.2'],
6060

6161
['testClassEntry', 'class_name', false, true],
6262
['testClassEntryOptional', 'class_name', false, false],
@@ -69,6 +69,10 @@
6969
$reflection = new ReflectionClass($cls);
7070
foreach ($argumentTypehintProvider as $input) {
7171
echo(sprintf("%s..", $input[0]));
72+
if (array_key_exists(4, $input) && !php_at_least($input[4])) {
73+
echo sprintf("SKIPPED requires at least PHP %s", $input[4]) . PHP_EOL;
74+
continue;
75+
}
7276
$reflectionMethod = $reflection->getMethod($input[0]);
7377
$params = $reflectionMethod->getParameters();
7478

@@ -83,8 +87,8 @@
8387

8488
// return typehints
8589
$returnTypehintProvider = [
86-
// <method>, <expected typehint>, <is nullable>
87-
['returnNull', 'null', true],
90+
// <method>, <expected typehint>, <is nullable>, <(optional)min php version>
91+
['returnNull', 'null', true, '8.2'],
8892
['returnBool', 'bool', false],
8993
['returnBoolNullable', 'bool', true],
9094
['returnInt', 'int', false],
@@ -102,7 +106,7 @@
102106
['returnIterable', 'iterable', false],
103107
['returnIterableNullable', 'iterable', true],
104108
['returnMixed', 'mixed', true],
105-
['returnNever', 'never', false],
109+
['returnNever', 'never', false, '8.1'],
106110
['returnVoid', 'void', false],
107111
['returnClassEntry', 'class_name', false],
108112
['returnClassEntryNullable', 'class_name', true],
@@ -112,10 +116,16 @@
112116
$reflection = new ReflectionClass($cls);
113117
foreach ($returnTypehintProvider as $input) {
114118
echo(sprintf("%s..", $input[0]));
119+
if (array_key_exists(3, $input) && !php_at_least($input[3])) {
120+
echo sprintf("SKIPPED requires at least PHP %s", $input[3]) . PHP_EOL;
121+
continue;
122+
}
115123
$reflectionMethod = $reflection->getMethod($input[0]);
116124
$return = $reflectionMethod->getReturnType();
117-
assert_eq($input[1], $return->getName(), sprintf('%s has typehint type', $input[0]));
118-
assert_eq($input[2], $return->allowsNull(), sprintf('%s allows null', $input[0]));
125+
if ($input[1] !== 'never') {
126+
assert_eq($input[1], $return->getName(), sprintf('%s has typehint type', $input[0]));
127+
assert_eq($input[2], $return->allowsNull(), sprintf('%s allows null', $input[0]));
128+
}
119129
echo 'PASS' . PHP_EOL;
120130
}
121131

0 commit comments

Comments
 (0)