Skip to content

Commit b1a832e

Browse files
committed
Adjust test after property type loading changes
Class loading is no longer relevant here, so just test general behavior.
1 parent 6a8681b commit b1a832e

File tree

2 files changed

+71
-62
lines changed

2 files changed

+71
-62
lines changed

Zend/tests/type_declarations/union_types/class_loading.phpt

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--TEST--
2+
Union types with multiple classes
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public X|Y|Z|int $prop;
8+
public function method(X|Y|Z|int $arg): X|Y|Z|int {
9+
return $arg;
10+
}
11+
}
12+
13+
// Check that nothing here triggers autoloading.
14+
spl_autoload_register(function($class) {
15+
echo "Loading $class\n";
16+
});
17+
18+
$test = new Test;
19+
20+
$test->prop = 42;
21+
var_dump($test->prop);
22+
var_dump($test->method(42));
23+
24+
$test->prop = "42";
25+
var_dump($test->prop);
26+
var_dump($test->method("42"));
27+
28+
try {
29+
$test->prop = new stdClass;
30+
} catch (TypeError $e) {
31+
echo $e->getMessage(), "\n";
32+
}
33+
34+
try {
35+
$test->method(new stdClass);
36+
} catch (TypeError $e) {
37+
echo $e->getMessage(), "\n";
38+
}
39+
40+
if (true) {
41+
class X {}
42+
}
43+
44+
$test->prop = new X;
45+
var_dump($test->prop);
46+
var_dump($test->method(new X));
47+
48+
if (true) {
49+
class Z {}
50+
}
51+
52+
$test->prop = new Z;
53+
var_dump($test->prop);
54+
var_dump($test->method(new Z));
55+
56+
?>
57+
--EXPECTF--
58+
int(42)
59+
int(42)
60+
int(42)
61+
int(42)
62+
Cannot assign stdClass to property Test::$prop of type X|Y|Z|int
63+
Argument 1 passed to Test::method() must be of type X|Y|Z|int, instance of stdClass given, called in %s on line %d
64+
object(X)#4 (0) {
65+
}
66+
object(X)#6 (0) {
67+
}
68+
object(Z)#6 (0) {
69+
}
70+
object(Z)#4 (0) {
71+
}

0 commit comments

Comments
 (0)