test.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // $Id: test.php 1641 2008-01-22 20:13:52Z pp11 $
  3. require_once dirname(__FILE__) . '/../../autorun.php';
  4. require_once dirname(__FILE__) . '/../testdox.php';
  5. // uncomment to see test dox in action
  6. //SimpleTest::prefer(new TestDoxReporter());
  7. class TestOfTestDoxReporter extends UnitTestCase
  8. {
  9. function testIsAnInstanceOfSimpleScorerAndReporter() {
  10. $dox = new TestDoxReporter();
  11. $this->assertIsA($dox, 'SimpleScorer');
  12. $this->assertIsA($dox, 'SimpleReporter');
  13. }
  14. function testOutputsNameOfTestCase() {
  15. $dox = new TestDoxReporter();
  16. ob_start();
  17. $dox->paintCaseStart('TestOfTestDoxReporter');
  18. $buffer = ob_get_clean();
  19. $this->assertWantedPattern('/^TestDoxReporter/', $buffer);
  20. }
  21. function testOutputOfTestCaseNameFilteredByConstructParameter() {
  22. $dox = new TestDoxReporter('/^(.*)Test$/');
  23. ob_start();
  24. $dox->paintCaseStart('SomeGreatWidgetTest');
  25. $buffer = ob_get_clean();
  26. $this->assertWantedPattern('/^SomeGreatWidget/', $buffer);
  27. }
  28. function testIfTest_case_patternIsEmptyAssumeEverythingMatches() {
  29. $dox = new TestDoxReporter('');
  30. ob_start();
  31. $dox->paintCaseStart('TestOfTestDoxReporter');
  32. $buffer = ob_get_clean();
  33. $this->assertWantedPattern('/^TestOfTestDoxReporter/', $buffer);
  34. }
  35. function testEmptyLineInsertedWhenCaseEnds() {
  36. $dox = new TestDoxReporter();
  37. ob_start();
  38. $dox->paintCaseEnd('TestOfTestDoxReporter');
  39. $buffer = ob_get_clean();
  40. $this->assertEqual("\n", $buffer);
  41. }
  42. function testPaintsTestMethodInTestDoxFormat() {
  43. $dox = new TestDoxReporter();
  44. ob_start();
  45. $dox->paintMethodStart('testSomeGreatTestCase');
  46. $buffer = ob_get_clean();
  47. $this->assertEqual("- some great test case", $buffer);
  48. unset($buffer);
  49. $random = rand(100, 200);
  50. ob_start();
  51. $dox->paintMethodStart("testRandomNumberIs{$random}");
  52. $buffer = ob_get_clean();
  53. $this->assertEqual("- random number is {$random}", $buffer);
  54. }
  55. function testDoesNotOutputAnythingOnNoneTestMethods() {
  56. $dox = new TestDoxReporter();
  57. ob_start();
  58. $dox->paintMethodStart('nonMatchingMethod');
  59. $buffer = ob_get_clean();
  60. $this->assertEqual('', $buffer);
  61. }
  62. function testPaintMethodAddLineBreak() {
  63. $dox = new TestDoxReporter();
  64. ob_start();
  65. $dox->paintMethodEnd('someMethod');
  66. $buffer = ob_get_clean();
  67. $this->assertEqual("\n", $buffer);
  68. $this->assertNoErrors();
  69. }
  70. function testProperlySpacesSingleLettersInMethodName() {
  71. $dox = new TestDoxReporter();
  72. ob_start();
  73. $dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod');
  74. $buffer = ob_get_clean();
  75. $this->assertEqual('- a very simple again a very simple method', $buffer);
  76. }
  77. function testOnFailureThisPrintsFailureNotice() {
  78. $dox = new TestDoxReporter();
  79. ob_start();
  80. $dox->paintFail();
  81. $buffer = ob_get_clean();
  82. $this->assertEqual(' [FAILED]', $buffer);
  83. }
  84. function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() {
  85. $dox = new TestDoxReporter();
  86. ob_start();
  87. $dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat');
  88. $buffer = ob_get_clean();
  89. $this->assertEqual(
  90. '- supports all uppercase test prefix even though i do not know why you would do that',
  91. $buffer
  92. );
  93. }
  94. }