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