Skip to content

Commit c0b03e3

Browse files
committed
Add additional class constant deprecation tests
1 parent 222db87 commit c0b03e3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
#[\Deprecated]: Using the value of a deprecated class constant as the deprecation message.
3+
--FILE--
4+
<?php
5+
6+
class Clazz {
7+
#[\Deprecated(self::TEST)]
8+
public const TEST = "from itself";
9+
10+
#[\Deprecated]
11+
public const TEST2 = "from another";
12+
13+
#[\Deprecated(self::TEST2)]
14+
public const TEST3 = 1;
15+
}
16+
17+
Clazz::TEST;
18+
Clazz::TEST3;
19+
20+
?>
21+
--EXPECTF--
22+
Deprecated: Constant Clazz::TEST is deprecated, from itself in %s on line %d
23+
24+
Deprecated: Constant Clazz::TEST2 is deprecated in %s on line %d
25+
26+
Deprecated: Constant Clazz::TEST3 is deprecated, from another in %s on line %d
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
#[\Deprecated]: Using the value of a deprecated class constant as the deprecation message with a throwing error handler.
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) {
7+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
8+
});
9+
10+
class Clazz {
11+
#[\Deprecated(self::TEST)]
12+
public const TEST = "from itself";
13+
14+
#[\Deprecated]
15+
public const TEST2 = "from another";
16+
17+
#[\Deprecated(self::TEST2)]
18+
public const TEST3 = 1;
19+
}
20+
21+
try {
22+
Clazz::TEST;
23+
} catch (ErrorException $e) {
24+
echo "Caught: ", $e->getMessage(), PHP_EOL;
25+
}
26+
27+
try {
28+
Clazz::TEST3;
29+
} catch (ErrorException $e) {
30+
echo "Caught: ", $e->getMessage(), PHP_EOL;
31+
}
32+
33+
?>
34+
--EXPECT--
35+
Caught: Constant Clazz::TEST is deprecated, from itself
36+
Caught: Constant Clazz::TEST2 is deprecated

0 commit comments

Comments
 (0)