PhpUnitOrderedCoversFixerTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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\Fixer\PhpUnit;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Filippo Tessarotto <zoeslam@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitOrderedCoversFixer
  19. */
  20. final class PhpUnitOrderedCoversFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public function provideFixCases()
  33. {
  34. return [
  35. 'skip on 1 or 0 occurrences' => [
  36. '<?php
  37. class FooTest extends \PHPUnit_Framework_TestCase {
  38. /**
  39. * @covers Foo
  40. * @params bool $bool
  41. * @return void
  42. */
  43. public function testMe() {}
  44. /**
  45. * @params bool $bool
  46. * @return void
  47. */
  48. public function testMe2() {}
  49. }
  50. ',
  51. ],
  52. 'base case' => [
  53. '<?php
  54. /**
  55. * @covers Bar
  56. * @covers Foo
  57. */
  58. class FooTest extends \PHPUnit_Framework_TestCase {}
  59. ',
  60. '<?php
  61. /**
  62. * @covers Foo
  63. * @covers Bar
  64. */
  65. class FooTest extends \PHPUnit_Framework_TestCase {}
  66. ',
  67. ],
  68. 'preserve positions if other docblock parts are present' => [
  69. '<?php
  70. /**
  71. * Comment 1
  72. * @covers Bar
  73. * Comment 3
  74. * @covers Foo
  75. * Comment 2
  76. */
  77. class FooTest extends \PHPUnit_Framework_TestCase {}
  78. ',
  79. '<?php
  80. /**
  81. * Comment 1
  82. * @covers Foo
  83. * Comment 2
  84. * @covers Bar
  85. * Comment 3
  86. */
  87. class FooTest extends \PHPUnit_Framework_TestCase {}
  88. ',
  89. ],
  90. 'case-insensitive' => [
  91. '<?php
  92. /**
  93. * @covers A
  94. * @covers c
  95. * @covers D
  96. * @covers E
  97. */
  98. class FooTest extends \PHPUnit_Framework_TestCase {}
  99. ',
  100. '<?php
  101. /**
  102. * @covers A
  103. * @covers E
  104. * @covers c
  105. * @covers D
  106. */
  107. class FooTest extends \PHPUnit_Framework_TestCase {}
  108. ',
  109. ],
  110. 'data provider' => [
  111. '<?php
  112. class FooTest extends \PHPUnit_Framework_TestCase
  113. {
  114. /**
  115. * @covers Bar
  116. * @dataProvider provide
  117. * @covers Foo
  118. */
  119. public function testMe() {}
  120. }
  121. ',
  122. '<?php
  123. class FooTest extends \PHPUnit_Framework_TestCase
  124. {
  125. /**
  126. * @covers Foo
  127. * @dataProvider provide
  128. * @covers Bar
  129. */
  130. public function testMe() {}
  131. }
  132. ',
  133. ],
  134. ];
  135. }
  136. }