AbstractReporterTestCase.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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\ReporterInterface;
  13. use PhpCsFixer\Report\ReportSummary;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. */
  20. abstract class AbstractReporterTestCase extends TestCase
  21. {
  22. /**
  23. * @var ReporterInterface
  24. */
  25. protected $reporter;
  26. protected function setUp()
  27. {
  28. $this->reporter = $this->createReporter();
  29. }
  30. final public function testGetFormat()
  31. {
  32. $this->assertSame(
  33. $this->getFormat(),
  34. $this->reporter->getFormat()
  35. );
  36. }
  37. /**
  38. * @param string $expectedReport
  39. * @param ReportSummary $reportSummary
  40. *
  41. * @dataProvider provideGenerateCases
  42. */
  43. final public function testGenerate($expectedReport, ReportSummary $reportSummary)
  44. {
  45. $actualReport = $this->reporter->generate($reportSummary);
  46. $this->assertFormat($expectedReport, $actualReport);
  47. }
  48. /**
  49. * @return array
  50. */
  51. final public function provideGenerateCases()
  52. {
  53. return array(
  54. 'no errors' => array(
  55. $this->createNoErrorReport(),
  56. new ReportSummary(
  57. array(),
  58. 0,
  59. 0,
  60. false,
  61. false,
  62. false
  63. ),
  64. ),
  65. 'simple' => array(
  66. $this->createSimpleReport(),
  67. new ReportSummary(
  68. array(
  69. 'someFile.php' => array(
  70. 'appliedFixers' => array('some_fixer_name_here'),
  71. ),
  72. ),
  73. 0,
  74. 0,
  75. false,
  76. false,
  77. false
  78. ),
  79. ),
  80. 'with diff' => array(
  81. $this->createWithDiffReport(),
  82. new ReportSummary(
  83. array(
  84. 'someFile.php' => array(
  85. 'appliedFixers' => array('some_fixer_name_here'),
  86. 'diff' => 'this text is a diff ;)',
  87. ),
  88. ),
  89. 0,
  90. 0,
  91. false,
  92. false,
  93. false
  94. ),
  95. ),
  96. 'with applied fixers' => array(
  97. $this->createWithAppliedFixersReport(),
  98. new ReportSummary(
  99. array(
  100. 'someFile.php' => array(
  101. 'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
  102. ),
  103. ),
  104. 0,
  105. 0,
  106. true,
  107. false,
  108. false
  109. ),
  110. ),
  111. 'with time and memory' => array(
  112. $this->createWithTimeAndMemoryReport(),
  113. new ReportSummary(
  114. array(
  115. 'someFile.php' => array(
  116. 'appliedFixers' => array('some_fixer_name_here'),
  117. ),
  118. ),
  119. 1234,
  120. 2.5 * 1024 * 1024,
  121. false,
  122. false,
  123. false
  124. ),
  125. ),
  126. 'complex' => array(
  127. $this->createComplexReport(),
  128. new ReportSummary(
  129. array(
  130. 'someFile.php' => array(
  131. 'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
  132. 'diff' => 'this text is a diff ;)',
  133. ),
  134. 'anotherFile.php' => array(
  135. 'appliedFixers' => array('another_fixer_name_here'),
  136. 'diff' => 'another diff here ;)',
  137. ),
  138. ),
  139. 1234,
  140. 2.5 * 1024 * 1024,
  141. true,
  142. true,
  143. true
  144. ),
  145. ),
  146. );
  147. }
  148. /**
  149. * @return ReporterInterface
  150. */
  151. abstract protected function createReporter();
  152. /**
  153. * @return string
  154. */
  155. abstract protected function getFormat();
  156. /**
  157. * @return string
  158. */
  159. abstract protected function createNoErrorReport();
  160. /**
  161. * @return string
  162. */
  163. abstract protected function createSimpleReport();
  164. /**
  165. * @return string
  166. */
  167. abstract protected function createWithDiffReport();
  168. /**
  169. * @return string
  170. */
  171. abstract protected function createWithAppliedFixersReport();
  172. /**
  173. * @return string
  174. */
  175. abstract protected function createWithTimeAndMemoryReport();
  176. /**
  177. * @return string
  178. */
  179. abstract protected function createComplexReport();
  180. /**
  181. * @param string $expected
  182. * @param string $input
  183. */
  184. abstract protected function assertFormat($expected, $input);
  185. }