Skip to content

Commit 7618d9a

Browse files
committed
fix tests back to 7.0
1 parent 5dbe212 commit 7618d9a

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

phper-sys/php_wrapper.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ phper_init_class_entry_handler(zend_class_entry *class_ce, void *argument);
3838
#define IS_NEVER 0x1B
3939
#endif
4040

41+
#ifndef IS_ITERABLE
42+
#define IS_ITERABLE 0x1C
43+
#endif
44+
45+
#ifndef IS_VOID
46+
#define IS_VOID 0x1D
47+
#endif
48+
4149
// ==================================================
4250
// zval apis:
4351
// ==================================================
@@ -500,10 +508,8 @@ phper_zend_begin_arg_with_return_obj_info_ex(bool return_reference,
500508
#define static
501509
#define const
502510
#if PHP_VERSION_ID >= 70400
503-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(info, return_reference,
504-
required_num_args,
505-
class_name, allow_null)
506-
#elif PHP_VERSION_ID >= 70200
511+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(info, return_reference, required_num_args, class_name, allow_null)
512+
#else
507513
ZEND_BEGIN_ARG_INFO_EX(info, 0, return_reference, required_num_args)
508514
#endif
509515
ZEND_END_ARG_INFO()
@@ -527,15 +533,10 @@ zend_internal_arg_info phper_zend_arg_info_with_type(bool pass_by_ref,
527533
zend_internal_arg_info info[] = {
528534
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value)
529535
};
530-
#elif PHP_VERSION_ID >= 70200
536+
#elif PHP_VERSION_ID >= 70000
531537
zend_internal_arg_info info[] = {
532538
ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null)
533539
};
534-
#else
535-
// PHP 7.0 and below: fallback
536-
zend_internal_arg_info info[] = {
537-
ZEND_ARG_INFO(pass_by_ref, name)
538-
};
539540
#endif
540541
info[0].name = name;
541542
return info[0];
@@ -561,9 +562,7 @@ zend_internal_arg_info phper_zend_arg_obj_info(bool pass_by_ref,
561562
#else
562563
zend_internal_arg_info info = {
563564
.name = name,
564-
.type = 0,
565565
.pass_by_reference = pass_by_ref,
566-
.is_variadic = 0
567566
};
568567
return info;
569568
#endif

tests/integration/tests/php/typehints.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
$argumentTypehintProvider = [
2424
// <method>, <expected typehint>, <is nullable>, <is required>, <(optional)min php version>
25-
['testString', 'string', false, true],
25+
['testString', 'string', false, true, '7.1'],
2626
['testStringOptional', 'string', false, false],
2727
['testStringNullable', 'string', true, true],
2828

@@ -48,13 +48,13 @@
4848
['testCallableOptional', 'callable', false, false],
4949
['testCallableNullable', 'callable', true, true],
5050

51-
['testObject', 'object', false, true],
52-
['testObjectOptional', 'object', false, false],
53-
['testObjectNullable', 'object', true, true],
51+
['testObject', 'object', false, true, '7.1'],
52+
['testObjectOptional', 'object', false, false, '7.1'],
53+
['testObjectNullable', 'object', true, true, '7.1'],
5454

55-
['testIterable', 'iterable', false, true],
56-
['testIterableOptional', 'iterable', false, false],
57-
['testIterableNullable', 'iterable', true, true],
55+
['testIterable', 'iterable', false, true, '7.1'],
56+
['testIterableOptional', 'iterable', false, false, '7.1'],
57+
['testIterableNullable', 'iterable', true, true, '7.1'],
5858

5959
['testNull', 'null', true, true, '8.2'],
6060

@@ -79,9 +79,14 @@
7979
assert_eq(1, count($params), 'has 1 param');
8080
$param = $params[0];
8181
$type = $param->getType();
82-
assert_eq($input[1], (string)$type->getName(), sprintf('%s has typehint type', $input[0]));
83-
assert_eq($input[2], $type->allowsNull(), sprintf('%s allows null', $input[0]));
84-
assert_eq($input[3], !$param->isOptional(), sprintf('%s is optional', $input[0]));
82+
if (PHP_VERSION_ID >= 70100) {
83+
assert_eq($input[1], (string)$type->getName(), sprintf('%s has typehint type', $input[0]));
84+
assert_eq($input[2], $type->allowsNull(), sprintf('%s allows null', $input[0]));
85+
assert_eq($input[3], !$param->isOptional(), sprintf('%s is optional', $input[0]));
86+
} else {
87+
//ReflectionType::getName doesn't exist until 7.1
88+
assert_eq($input[1], (string)$type);
89+
}
8590
echo "PASS" . PHP_EOL;
8691
}
8792

@@ -122,29 +127,31 @@
122127
}
123128
$reflectionMethod = $reflection->getMethod($input[0]);
124129
$return = $reflectionMethod->getReturnType();
125-
if ($input[1] !== 'never') {
130+
if ($input[1] !== 'never' && PHP_VERSION_ID > 70100) {
126131
assert_eq($input[1], $return->getName(), sprintf('%s has typehint type', $input[0]));
127132
assert_eq($input[2], $return->allowsNull(), sprintf('%s allows null', $input[0]));
128133
}
129134
echo 'PASS' . PHP_EOL;
130135
}
131136

132-
// test class entry type-hints with an instance
133-
$foo = new class implements \IntegrationTest\TypeHints\IFoo {
134-
private $value;
135-
public function getValue(): string {
136-
return $this->value;
137-
}
138-
public function setValue($value): void {
139-
$this->value = $value;
140-
}
141-
};
142-
143-
$foo->setValue('hello');
144-
assert_eq('hello', $foo->getValue());
145-
146-
$handler = new \IntegrationTest\TypeHints\FooHandler();
147-
assert_eq($foo, $handler->handle($foo));
137+
if (PHP_VERSION_ID > 70100) {
138+
// test class entry type-hints with an instance
139+
$foo = new class implements \IntegrationTest\TypeHints\IFoo {
140+
private $value;
141+
public function getValue(): string {
142+
return $this->value;
143+
}
144+
public function setValue($value): void {
145+
$this->value = $value;
146+
}
147+
};
148+
149+
$foo->setValue('hello');
150+
assert_eq('hello', $foo->getValue());
151+
152+
$handler = new \IntegrationTest\TypeHints\FooHandler();
153+
assert_eq($foo, $handler->handle($foo));
154+
}
148155

149156
$argumentDefaultValueProvider = [
150157
// <method>, <expected default value>, <(optional) min php version>

0 commit comments

Comments
 (0)