PageRenderTime 34ms CodeModel.GetById 20ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/php/director_exception_runme.php

#
PHP | 78 lines | 56 code | 11 blank | 11 comment | 2 complexity | a9d673532bcd5ceb106d260588085daf MD5 | raw file
 1<?php
 2
 3require "tests.php";
 4require "director_exception.php";
 5
 6// No new functions
 7check::functions(array(foo_ping,foo_pong,launder,bar_ping,bar_pong,bar_pang));
 8// No new classes
 9check::classes(array(director_exception,Foo,Exception1,Exception2,Base,Bar));
10// now new vars
11check::globals(array());
12
13class MyException extends Exception {
14  function __construct($a, $b) {
15    $this->msg = $a . $b;
16  }
17}
18
19class MyFoo extends Foo {
20  function ping() {
21    throw new Exception("MyFoo::ping() EXCEPTION");
22  }
23}
24
25class MyFoo2 extends Foo {
26  function ping() {
27    return true;
28  }
29}
30
31class MyFoo3 extends Foo {
32  function ping() {
33    throw new MyException("foo", "bar");
34  }
35}
36
37# Check that the Exception raised by MyFoo.ping() is returned by 
38# MyFoo.pong().
39$ok = 0;
40$a = new MyFoo();
41# TODO: Currently we do not track the dynamic type of returned 
42# objects, so we skip the launder() call.
43#$b = director_exception::launder($a);
44$b = $a;
45try {
46  $b->pong();
47} catch (Exception $e) {
48  $ok = 1;
49  check::equal($e->getMessage(), "MyFoo::ping() EXCEPTION", "Unexpected error message #1");
50}
51check::equal($ok, 1, "Got no exception while expected one #1");
52
53# Check that the director can return an exception which requires two 
54# arguments to the constructor, without mangling it.
55$ok = 0;
56$a = new MyFoo3();
57#$b = director_exception::launder($a);
58$b = $a;
59try {
60  $b->pong();
61} catch (Exception $e) {
62  $ok = 1;
63  check::equal($e->msg, "foobar", "Unexpected error message #2");
64}
65check::equal($ok, 1, "Got no exception while expected one #2");
66
67try {
68  throw new Exception2();
69} catch (Exception2 $e2) {
70}
71
72try {
73  throw new Exception1();
74} catch (Exception1 $e1) {
75}
76
77check::done();
78?>