PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/test/simpletest/test/errors_test.php

https://github.com/slim/phtpasswd
PHP | 139 lines | 116 code | 23 blank | 0 comment | 0 complexity | 06ffeb07498dcdb1a9bbfe6a2a3d048c MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require_once(dirname(__FILE__) . '/../errors.php');
  3. class TestOfErrorQueue extends UnitTestCase {
  4. function setUp() {
  5. $queue = &SimpleErrorQueue::instance();
  6. $queue->clear();
  7. }
  8. function tearDown() {
  9. $queue = &SimpleErrorQueue::instance();
  10. $queue->clear();
  11. }
  12. function testSingleton() {
  13. $this->assertReference(
  14. SimpleErrorQueue::instance(),
  15. SimpleErrorQueue::instance());
  16. $this->assertIsA(SimpleErrorQueue::instance(), 'SimpleErrorQueue');
  17. }
  18. function testEmpty() {
  19. $queue = &SimpleErrorQueue::instance();
  20. $this->assertTrue($queue->isEmpty());
  21. $this->assertFalse($queue->extract());
  22. }
  23. function testOrder() {
  24. $queue = &SimpleErrorQueue::instance();
  25. $queue->add(1024, 'Ouch', 'here.php', 100, array());
  26. $this->assertFalse($queue->isEmpty());
  27. $queue->add(512, 'Yuk', 'there.php', 101, array());
  28. $this->assertEqual(
  29. $queue->extract(),
  30. array(1024, 'Ouch', 'here.php', 100, array()));
  31. $this->assertEqual(
  32. $queue->extract(),
  33. array(512, 'Yuk', 'there.php', 101, array()));
  34. $this->assertFalse($queue->extract());
  35. }
  36. }
  37. class TestOfErrorTrap extends UnitTestCase {
  38. var $_old;
  39. function setUp() {
  40. $this->_old = error_reporting(E_ALL);
  41. set_error_handler('simpleTestErrorHandler');
  42. }
  43. function tearDown() {
  44. restore_error_handler();
  45. error_reporting($this->_old);
  46. }
  47. function testTrappedErrorPlacedInQueue() {
  48. $queue = &SimpleErrorQueue::instance();
  49. $this->assertFalse($queue->extract());
  50. trigger_error('Ouch!');
  51. list($severity, $message, $file, $line, $globals) = $queue->extract();
  52. $this->assertEqual($message, 'Ouch!');
  53. $this->assertEqual($file, __FILE__);
  54. $this->assertFalse($queue->extract());
  55. }
  56. }
  57. class TestOfErrors extends UnitTestCase {
  58. var $_old;
  59. function setUp() {
  60. $this->_old = error_reporting(E_ALL);
  61. }
  62. function tearDown() {
  63. error_reporting($this->_old);
  64. }
  65. function testDefaultWhenAllReported() {
  66. error_reporting(E_ALL);
  67. trigger_error('Ouch!');
  68. $this->assertError('Ouch!');
  69. }
  70. function testNoticeWhenReported() {
  71. error_reporting(E_ALL);
  72. trigger_error('Ouch!', E_USER_NOTICE);
  73. $this->assertError('Ouch!');
  74. }
  75. function testWarningWhenReported() {
  76. error_reporting(E_ALL);
  77. trigger_error('Ouch!', E_USER_WARNING);
  78. $this->assertError('Ouch!');
  79. }
  80. function testErrorWhenReported() {
  81. error_reporting(E_ALL);
  82. trigger_error('Ouch!', E_USER_ERROR);
  83. $this->assertError('Ouch!');
  84. }
  85. function testNoNoticeWhenNotReported() {
  86. error_reporting(0);
  87. trigger_error('Ouch!', E_USER_NOTICE);
  88. $this->assertNoErrors();
  89. }
  90. function testNoWarningWhenNotReported() {
  91. error_reporting(0);
  92. trigger_error('Ouch!', E_USER_WARNING);
  93. $this->assertNoErrors();
  94. }
  95. function testNoErrorWhenNotReported() {
  96. error_reporting(0);
  97. trigger_error('Ouch!', E_USER_ERROR);
  98. $this->assertNoErrors();
  99. }
  100. function testNoticeSuppressedWhenReported() {
  101. error_reporting(E_ALL);
  102. @trigger_error('Ouch!', E_USER_NOTICE);
  103. $this->assertNoErrors();
  104. }
  105. function testWarningSuppressedWhenReported() {
  106. error_reporting(E_ALL);
  107. @trigger_error('Ouch!', E_USER_WARNING);
  108. $this->assertNoErrors();
  109. }
  110. function testErrorSuppressedWhenReported() {
  111. error_reporting(E_ALL);
  112. @trigger_error('Ouch!', E_USER_ERROR);
  113. $this->assertNoErrors();
  114. }
  115. }
  116. ?>