Skip to content

Commit 0b3f3b4

Browse files
committed
Add tests for non coercion
1 parent 581f4f6 commit 0b3f3b4

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
No coercion should be applied to type false
3+
--FILE--
4+
<?php
5+
6+
function test(false $v) { var_dump($v); }
7+
8+
try {
9+
test(0);
10+
} catch (\TypeError $e) {
11+
echo $e->getMessage(), \PHP_EOL;
12+
}
13+
try {
14+
test('');
15+
} catch (\TypeError $e) {
16+
echo $e->getMessage(), \PHP_EOL;
17+
}
18+
try {
19+
test([]);
20+
} catch (\TypeError $e) {
21+
echo $e->getMessage(), \PHP_EOL;
22+
}
23+
24+
?>
25+
--EXPECT--
26+
test(): Argument #1 ($v) must be of type false, int given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/false_no_coercion.php on line 6
27+
test(): Argument #1 ($v) must be of type false, string given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/false_no_coercion.php on line 11
28+
test(): Argument #1 ($v) must be of type false, array given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/false_no_coercion.php on line 16
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
No coercion should be applied to type true
3+
--FILE--
4+
<?php
5+
6+
function test(true $v) { var_dump($v); }
7+
8+
try {
9+
test(1);
10+
} catch (\TypeError $e) {
11+
echo $e->getMessage(), \PHP_EOL;
12+
}
13+
try {
14+
test('1');
15+
} catch (\TypeError $e) {
16+
echo $e->getMessage(), \PHP_EOL;
17+
}
18+
try {
19+
test([1]);
20+
} catch (\TypeError $e) {
21+
echo $e->getMessage(), \PHP_EOL;
22+
}
23+
try {
24+
test(new stdClass());
25+
} catch (\TypeError $e) {
26+
echo $e->getMessage(), \PHP_EOL;
27+
}
28+
29+
?>
30+
--EXPECT--
31+
test(): Argument #1 ($v) must be of type true, int given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/true_no_coercion.php on line 6
32+
test(): Argument #1 ($v) must be of type true, string given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/true_no_coercion.php on line 11
33+
test(): Argument #1 ($v) must be of type true, array given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/true_no_coercion.php on line 16
34+
test(): Argument #1 ($v) must be of type true, stdClass given, called in /home/girgias/Dev/php-src/Zend/tests/type_declarations/literral_types/true_no_coercion.php on line 21
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
true can be used as a standalone type even with implicit nullability
3+
--FILE--
4+
<?php
5+
6+
function test(true $v = null) {}
7+
8+
?>
9+
===DONE===
10+
--EXPECT--
11+
===DONE===

0 commit comments

Comments
 (0)