GitlabReporterTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\Application;
  14. use PhpCsFixer\Console\Report\FixReport\GitlabReporter;
  15. use PhpCsFixer\Console\Report\FixReport\ReporterInterface;
  16. use PhpCsFixer\Tests\Test\Assert\AssertJsonSchemaTrait;
  17. /**
  18. * @author Hans-Christian Otto <c.otto@suora.com>
  19. *
  20. * @internal
  21. *
  22. * @covers \PhpCsFixer\Console\Report\FixReport\GitlabReporter
  23. */
  24. final class GitlabReporterTest extends AbstractReporterTestCase
  25. {
  26. use AssertJsonSchemaTrait;
  27. protected function createReporter(): ReporterInterface
  28. {
  29. return new GitlabReporter();
  30. }
  31. protected function getFormat(): string
  32. {
  33. return 'gitlab';
  34. }
  35. protected static function createNoErrorReport(): string
  36. {
  37. return '[]';
  38. }
  39. protected static function createSimpleReport(): string
  40. {
  41. $about = Application::getAbout();
  42. return <<<JSON
  43. [{
  44. "categories": ["Style"],
  45. "check_name": "PHP-CS-Fixer.some_fixer_name_here",
  46. "description": "PHP-CS-Fixer.some_fixer_name_here by {$about}",
  47. "fingerprint": "ad098ea6ea7a28dd85dfcdfc9e2bded0",
  48. "severity": "minor",
  49. "location": {
  50. "path": "someFile.php",
  51. "lines": {
  52. "begin": 2,
  53. "end": 7
  54. }
  55. }
  56. }]
  57. JSON;
  58. }
  59. protected static function createWithDiffReport(): string
  60. {
  61. return self::createSimpleReport();
  62. }
  63. protected static function createWithAppliedFixersReport(): string
  64. {
  65. $about = Application::getAbout();
  66. return <<<JSON
  67. [{
  68. "categories": ["Style"],
  69. "check_name": "PHP-CS-Fixer.some_fixer_name_here_1",
  70. "description": "PHP-CS-Fixer.some_fixer_name_here_1 by {$about}",
  71. "fingerprint": "b74e9385c8ae5b1f575c9c8226c7deff",
  72. "severity": "minor",
  73. "location": {
  74. "path": "someFile.php",
  75. "lines": {
  76. "begin": 0,
  77. "end": 0
  78. }
  79. }
  80. },{
  81. "categories": ["Style"],
  82. "check_name": "PHP-CS-Fixer.some_fixer_name_here_2",
  83. "description": "PHP-CS-Fixer.some_fixer_name_here_2 by {$about}",
  84. "fingerprint": "acad4672140c737a83c18d1474d84074",
  85. "severity": "minor",
  86. "location": {
  87. "path": "someFile.php",
  88. "lines": {
  89. "begin": 0,
  90. "end": 0
  91. }
  92. }
  93. }]
  94. JSON;
  95. }
  96. protected static function createWithTimeAndMemoryReport(): string
  97. {
  98. return self::createSimpleReport();
  99. }
  100. protected static function createComplexReport(): string
  101. {
  102. $about = Application::getAbout();
  103. return <<<JSON
  104. [{
  105. "categories": ["Style"],
  106. "check_name": "PHP-CS-Fixer.some_fixer_name_here_1",
  107. "description": "PHP-CS-Fixer.some_fixer_name_here_1 by {$about}",
  108. "fingerprint": "b74e9385c8ae5b1f575c9c8226c7deff",
  109. "severity": "minor",
  110. "location": {
  111. "path": "someFile.php",
  112. "lines": {
  113. "begin": 0,
  114. "end": 0
  115. }
  116. }
  117. },{
  118. "categories": ["Style"],
  119. "check_name": "PHP-CS-Fixer.some_fixer_name_here_2",
  120. "description": "PHP-CS-Fixer.some_fixer_name_here_2 by {$about}",
  121. "fingerprint": "acad4672140c737a83c18d1474d84074",
  122. "severity": "minor",
  123. "location": {
  124. "path": "someFile.php",
  125. "lines": {
  126. "begin": 0,
  127. "end": 0
  128. }
  129. }
  130. },{
  131. "categories": ["Style"],
  132. "check_name": "PHP-CS-Fixer.another_fixer_name_here",
  133. "description": "PHP-CS-Fixer.another_fixer_name_here by {$about}",
  134. "fingerprint": "30e86e533dac0f1b93bbc3a55c6908f8",
  135. "severity": "minor",
  136. "location": {
  137. "path": "anotherFile.php",
  138. "lines": {
  139. "begin": 0,
  140. "end": 0
  141. }
  142. }
  143. }]
  144. JSON;
  145. }
  146. protected function assertFormat(string $expected, string $input): void
  147. {
  148. self::assertJsonSchema(__DIR__.'/../../../../doc/schemas/fix/codeclimate.json', $input);
  149. self::assertJsonStringEqualsJsonString($expected, $input);
  150. }
  151. }