/src/test/php/PHP/Depend/TextUI/ResultPrinterTest.php

https://github.com/Proudio-Interactive/pdepend · PHP · 173 lines · 68 code · 21 blank · 84 comment · 3 complexity · 732cebe4b1f213d666585a7c41050ea8 MD5 · raw file

  1. <?php
  2. /**
  3. * This file is part of PHP_Depend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2011, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @category QualityAssurance
  40. * @package PHP_Depend
  41. * @subpackage TextUI
  42. * @author Manuel Pichler <mapi@pdepend.org>
  43. * @copyright 2008-2011 Manuel Pichler. All rights reserved.
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. * @version SVN: $Id$
  46. * @link http://pdepend.org/
  47. */
  48. require_once dirname(__FILE__) . '/../AbstractTest.php';
  49. /**
  50. * Test case for the default text ui result printer.
  51. *
  52. * @category QualityAssurance
  53. * @package PHP_Depend
  54. * @subpackage TextUI
  55. * @author Manuel Pichler <mapi@pdepend.org>
  56. * @copyright 2008-2011 Manuel Pichler. All rights reserved.
  57. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  58. * @version Release: @package_version@
  59. * @link http://pdepend.org/
  60. *
  61. * @covers PHP_Depend_TextUI_ResultPrinter
  62. */
  63. class PHP_Depend_TextUI_ResultPrinterTest extends PHP_Depend_AbstractTest
  64. {
  65. /**
  66. * Tests the output for a single file entry.
  67. *
  68. * @return void
  69. */
  70. public function testResultPrinterOutputForSingleEntry()
  71. {
  72. // Create dummy objects
  73. $builder = new PHP_Depend_Builder_Default();
  74. $tokenizer = new PHP_Depend_Tokenizer_Internal();
  75. $tokenizer->setSourceFile(__FILE__);
  76. $printer = new PHP_Depend_TextUI_ResultPrinter();
  77. ob_start();
  78. $printer->startFileParsing($tokenizer);
  79. $printer->endParseProcess($builder);
  80. $actual = ob_get_contents();
  81. ob_end_clean();
  82. $expected = ". 1\n\n";
  83. $this->assertEquals($expected, $actual);
  84. }
  85. /**
  86. * Tests the result printer with multiple entries.
  87. *
  88. * @return void
  89. */
  90. public function testResultPrinterOutputForMultipleEntries()
  91. {
  92. // Create dummy objects
  93. $builder = new PHP_Depend_Builder_Default();
  94. $tokenizer = new PHP_Depend_Tokenizer_Internal();
  95. $tokenizer->setSourceFile(__FILE__);
  96. $printer = new PHP_Depend_TextUI_ResultPrinter();
  97. ob_start();
  98. for ($i = 0; $i < 73; ++$i) {
  99. $printer->startFileParsing($tokenizer);
  100. }
  101. $printer->endParseProcess($builder);
  102. $actual = ob_get_contents();
  103. ob_end_clean();
  104. $expected = "............................................................ 60\n"
  105. . "............. 73\n\n";
  106. $this->assertEquals($expected, $actual);
  107. }
  108. /**
  109. * Tests the result printer with multiple entries.
  110. *
  111. * @return void
  112. */
  113. public function testResultPrinterForMultipleEntries()
  114. {
  115. // Create dummy objects
  116. $method = new PHP_Depend_Code_Method('method');
  117. $analyzer = new PHP_Depend_Metrics_ClassLevel_Analyzer();
  118. $printer = new PHP_Depend_TextUI_ResultPrinter();
  119. ob_start();
  120. for ($i = 0; $i < 1401; ++$i) {
  121. $printer->startVisitMethod($method);
  122. }
  123. $printer->endAnalyzer($analyzer);
  124. $actual = ob_get_contents();
  125. ob_end_clean();
  126. $expected = "............................................................ 1200\n"
  127. . ".......... 1401\n\n";
  128. $this->assertEquals($expected, $actual);
  129. }
  130. /**
  131. * Tests the result printer with multiple entries.
  132. *
  133. * @return void
  134. */
  135. public function testResultPrinterForCompleteLine()
  136. {
  137. // Create dummy objects
  138. $method = new PHP_Depend_Code_Method('method');
  139. $analyzer = new PHP_Depend_Metrics_ClassLevel_Analyzer();
  140. $printer = new PHP_Depend_TextUI_ResultPrinter();
  141. ob_start();
  142. for ($i = 0; $i < 2400; ++$i) {
  143. $printer->startVisitMethod($method);
  144. }
  145. $printer->endAnalyzer($analyzer);
  146. $actual = ob_get_contents();
  147. ob_end_clean();
  148. $expected = "............................................................ 1200\n"
  149. . "............................................................ 2400\n\n";
  150. $this->assertEquals($expected, $actual);
  151. }
  152. }