summaryrefslogtreecommitdiff
path: root/ext/zend_test/tests/observer_exception_01.phpt
blob: fd49c0618b5bd932bfd01c067140ce0079780922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--TEST--
Observer: Basic observability of userland functions with uncaught exceptions
--SKIPIF--
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
--INI--
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
--FILE--
<?php
function foo()
{
    static $callCount = 0;
    echo 'Call #' . $callCount . PHP_EOL;
    if (++$callCount == 3) {
        throw new RuntimeException('Third time is a charm');
    }
}

foo();
foo();
foo();

echo 'You should not see this' . PHP_EOL;
?>
--EXPECTF--
<!-- init '%s/observer_exception_%d.php' -->
<file '%s/observer_exception_%d.php'>
  <!-- init foo() -->
  <foo>
Call #0
  </foo>
  <foo>
Call #1
  </foo>
  <foo>
Call #2
    <!-- Exception: RuntimeException -->
  </foo>
  <!-- Exception: RuntimeException -->
</file '%s/observer_exception_%d.php'>

Fatal error: Uncaught RuntimeException: Third time is a charm in %s/observer_exception_%d.php:%d
Stack trace:
#0 %s/observer_exception_%d.php(%d): foo()
#1 {main}
  thrown in %s/observer_exception_%d.php on line %d