Skip to content

Commit 34ce321

Browse files
committed
Add test
1 parent 14c9a5a commit 34ce321

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Invoke destructors after bailout
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
?>
7+
--FILE--
8+
<?php
9+
10+
final class StatCounter {
11+
private static self $instance;
12+
public static function get(): self {
13+
return self::$instance ??= new self;
14+
}
15+
16+
private array $stats = [];
17+
18+
private function __construct() {}
19+
20+
public function __destruct() {
21+
echo "Sending stats: ".json_encode($this->stats)."\n";
22+
exit(0);
23+
}
24+
25+
public function inc(string $key, int $by = 1): void {
26+
$this->stats[$key] ??= 0;
27+
$this->stats[$key] += $by;
28+
}
29+
}
30+
31+
StatCounter::get()->inc('test');
32+
StatCounter::get()->inc('test2');
33+
34+
set_time_limit(1);
35+
while (1);
36+
37+
?>
38+
--EXPECTF--
39+
40+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
41+
Sending stats: {"test":1,"test2":1}

0 commit comments

Comments
 (0)