|
22 | 22 |
|
23 | 23 | $argumentTypehintProvider = [ |
24 | 24 | // <method>, <expected typehint>, <is nullable>, <is required>, <(optional)min php version> |
25 | | - ['testString', 'string', false, true], |
| 25 | + ['testString', 'string', false, true, '7.1'], |
26 | 26 | ['testStringOptional', 'string', false, false], |
27 | 27 | ['testStringNullable', 'string', true, true], |
28 | 28 |
|
|
48 | 48 | ['testCallableOptional', 'callable', false, false], |
49 | 49 | ['testCallableNullable', 'callable', true, true], |
50 | 50 |
|
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'], |
54 | 54 |
|
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'], |
58 | 58 |
|
59 | 59 | ['testNull', 'null', true, true, '8.2'], |
60 | 60 |
|
|
79 | 79 | assert_eq(1, count($params), 'has 1 param'); |
80 | 80 | $param = $params[0]; |
81 | 81 | $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 | + } |
85 | 90 | echo "PASS" . PHP_EOL; |
86 | 91 | } |
87 | 92 |
|
|
122 | 127 | } |
123 | 128 | $reflectionMethod = $reflection->getMethod($input[0]); |
124 | 129 | $return = $reflectionMethod->getReturnType(); |
125 | | - if ($input[1] !== 'never') { |
| 130 | + if ($input[1] !== 'never' && PHP_VERSION_ID > 70100) { |
126 | 131 | assert_eq($input[1], $return->getName(), sprintf('%s has typehint type', $input[0])); |
127 | 132 | assert_eq($input[2], $return->allowsNull(), sprintf('%s allows null', $input[0])); |
128 | 133 | } |
129 | 134 | echo 'PASS' . PHP_EOL; |
130 | 135 | } |
131 | 136 |
|
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 | +} |
148 | 155 |
|
149 | 156 | $argumentDefaultValueProvider = [ |
150 | 157 | // <method>, <expected default value>, <(optional) min php version> |
|
0 commit comments