TextReporterTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Report;
  12. use PhpCsFixer\Report\ReportSummary;
  13. use PhpCsFixer\Report\TextReporter;
  14. /**
  15. * @author Boris Gorbylev <ekho@ekho.name>
  16. *
  17. * @internal
  18. */
  19. final class TextReporterTest extends \PHPUnit_Framework_TestCase
  20. {
  21. /** @var TextReporter */
  22. private $reporter;
  23. protected function setUp()
  24. {
  25. $this->reporter = new TextReporter();
  26. }
  27. /**
  28. * @covers \PhpCsFixer\Report\TextReporter::getFormat
  29. */
  30. public function testGetFormat()
  31. {
  32. $this->assertSame('txt', $this->reporter->getFormat());
  33. }
  34. public function testGenerateNoErrors()
  35. {
  36. $expectedReport = <<<'TEXT'
  37. TEXT;
  38. $this->assertSame(
  39. $expectedReport,
  40. $this->reporter->generate(
  41. new ReportSummary(
  42. array(),
  43. 0,
  44. 0,
  45. false,
  46. false,
  47. false
  48. )
  49. )
  50. );
  51. }
  52. public function testGenerateSimple()
  53. {
  54. $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
  55. 1) someFile.php
  56. TEXT
  57. );
  58. $this->assertSame(
  59. $expectedReport,
  60. $this->reporter->generate(
  61. new ReportSummary(
  62. array(
  63. 'someFile.php' => array(
  64. 'appliedFixers' => array('some_fixer_name_here'),
  65. ),
  66. ),
  67. 0,
  68. 0,
  69. false,
  70. false,
  71. false
  72. )
  73. )
  74. );
  75. }
  76. public function testGenerateWithDiff()
  77. {
  78. $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
  79. 1) someFile.php
  80. ---------- begin diff ----------
  81. this text is a diff ;)
  82. ----------- end diff -----------
  83. TEXT
  84. );
  85. $this->assertSame(
  86. $expectedReport,
  87. $this->reporter->generate(
  88. new ReportSummary(
  89. array(
  90. 'someFile.php' => array(
  91. 'appliedFixers' => array('some_fixer_name_here'),
  92. 'diff' => 'this text is a diff ;)',
  93. ),
  94. ),
  95. 0,
  96. 0,
  97. false,
  98. false,
  99. false
  100. )
  101. )
  102. );
  103. }
  104. public function testGenerateWithAppliedFixers()
  105. {
  106. $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
  107. 1) someFile.php (some_fixer_name_here)
  108. TEXT
  109. );
  110. $this->assertSame(
  111. $expectedReport,
  112. $this->reporter->generate(
  113. new ReportSummary(
  114. array(
  115. 'someFile.php' => array(
  116. 'appliedFixers' => array('some_fixer_name_here'),
  117. ),
  118. ),
  119. 0,
  120. 0,
  121. true,
  122. false,
  123. false
  124. )
  125. )
  126. );
  127. }
  128. public function testGenerateWithTimeAndMemory()
  129. {
  130. $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
  131. 1) someFile.php
  132. Fixed all files in 1.234 seconds, 2.500 MB memory used
  133. TEXT
  134. );
  135. $this->assertSame(
  136. $expectedReport,
  137. $this->reporter->generate(
  138. new ReportSummary(
  139. array(
  140. 'someFile.php' => array(
  141. 'appliedFixers' => array('some_fixer_name_here'),
  142. ),
  143. ),
  144. 1234,
  145. 2.5 * 1024 * 1024,
  146. false,
  147. false,
  148. false
  149. )
  150. )
  151. );
  152. }
  153. public function testGenerateComplexWithDecoratedOutput()
  154. {
  155. $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
  156. 1) someFile.php (<comment>some_fixer_name_here</comment>)
  157. <comment> ---------- begin diff ----------</comment>
  158. this text is a diff ;)
  159. <comment> ----------- end diff -----------</comment>
  160. 2) anotherFile.php (<comment>another_fixer_name_here</comment>)
  161. <comment> ---------- begin diff ----------</comment>
  162. another diff here ;)
  163. <comment> ----------- end diff -----------</comment>
  164. Checked all files in 1.234 seconds, 2.500 MB memory used
  165. TEXT
  166. );
  167. $this->assertSame(
  168. $expectedReport,
  169. $this->reporter->generate(
  170. new ReportSummary(
  171. array(
  172. 'someFile.php' => array(
  173. 'appliedFixers' => array('some_fixer_name_here'),
  174. 'diff' => 'this text is a diff ;)',
  175. ),
  176. 'anotherFile.php' => array(
  177. 'appliedFixers' => array('another_fixer_name_here'),
  178. 'diff' => 'another diff here ;)',
  179. ),
  180. ),
  181. 1234,
  182. 2.5 * 1024 * 1024,
  183. true,
  184. true,
  185. true
  186. )
  187. )
  188. );
  189. }
  190. }