TextReporterTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Console\Report\FixReport;
  13. use PhpCsFixer\Console\Report\FixReport\ReporterInterface;
  14. use PhpCsFixer\Console\Report\FixReport\TextReporter;
  15. /**
  16. * @author Boris Gorbylev <ekho@ekho.name>
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Console\Report\FixReport\TextReporter
  22. */
  23. final class TextReporterTest extends AbstractReporterTestCase
  24. {
  25. protected static function createNoErrorReport(): string
  26. {
  27. return <<<'TEXT'
  28. TEXT;
  29. }
  30. protected static function createSimpleReport(): string
  31. {
  32. return str_replace(
  33. "\n",
  34. PHP_EOL,
  35. <<<'TEXT'
  36. 1) someFile.php
  37. ---------- begin diff ----------
  38. --- Original
  39. +++ New
  40. @@ -2,7 +2,7 @@
  41. class Foo
  42. {
  43. - public function bar($foo = 1, $bar)
  44. + public function bar($foo, $bar)
  45. {
  46. }
  47. }
  48. ----------- end diff -----------
  49. TEXT
  50. );
  51. }
  52. protected static function createWithDiffReport(): string
  53. {
  54. return str_replace(
  55. "\n",
  56. PHP_EOL,
  57. <<<'TEXT'
  58. 1) someFile.php
  59. ---------- begin diff ----------
  60. --- Original
  61. +++ New
  62. @@ -2,7 +2,7 @@
  63. class Foo
  64. {
  65. - public function bar($foo = 1, $bar)
  66. + public function bar($foo, $bar)
  67. {
  68. }
  69. }
  70. ----------- end diff -----------
  71. TEXT
  72. );
  73. }
  74. protected static function createWithAppliedFixersReport(): string
  75. {
  76. return str_replace(
  77. "\n",
  78. PHP_EOL,
  79. <<<'TEXT'
  80. 1) someFile.php (some_fixer_name_here_1, some_fixer_name_here_2)
  81. TEXT
  82. );
  83. }
  84. protected static function createWithTimeAndMemoryReport(): string
  85. {
  86. return str_replace(
  87. "\n",
  88. PHP_EOL,
  89. <<<'TEXT'
  90. 1) someFile.php
  91. ---------- begin diff ----------
  92. --- Original
  93. +++ New
  94. @@ -2,7 +2,7 @@
  95. class Foo
  96. {
  97. - public function bar($foo = 1, $bar)
  98. + public function bar($foo, $bar)
  99. {
  100. }
  101. }
  102. ----------- end diff -----------
  103. Fixed 1 of 10 files in 1.234 seconds, 2.50 MB memory used
  104. TEXT
  105. );
  106. }
  107. protected static function createComplexReport(): string
  108. {
  109. return str_replace(
  110. "\n",
  111. PHP_EOL,
  112. <<<'TEXT'
  113. 1) someFile.php (<comment>some_fixer_name_here_1, some_fixer_name_here_2</comment>)
  114. <comment> ---------- begin diff ----------</comment>
  115. this text is a diff ;)
  116. <comment> ----------- end diff -----------</comment>
  117. 2) anotherFile.php (<comment>another_fixer_name_here</comment>)
  118. <comment> ---------- begin diff ----------</comment>
  119. another diff here ;)
  120. <comment> ----------- end diff -----------</comment>
  121. Found 2 of 10 files that can be fixed in 1.234 seconds, 2.50 MB memory used
  122. TEXT
  123. );
  124. }
  125. protected function createReporter(): ReporterInterface
  126. {
  127. return new TextReporter();
  128. }
  129. protected function getFormat(): string
  130. {
  131. return 'txt';
  132. }
  133. protected function assertFormat(string $expected, string $input): void
  134. {
  135. self::assertSame($expected, $input);
  136. }
  137. }