NoLeadingImportSlashFixerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\Import;
  12. use PhpCsFixer\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Carlos Cirello <carlos.cirello.nl@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer
  19. */
  20. final class NoLeadingImportSlashFixerTest 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. /**
  33. * @param string $expected
  34. * @param null|string $input
  35. *
  36. * @dataProvider provideFix54Cases
  37. * @requires PHP 5.4
  38. */
  39. public function testFix54($expected, $input = null)
  40. {
  41. $this->doTest($expected, $input);
  42. }
  43. public function provideFixCases()
  44. {
  45. return array(
  46. array(
  47. '<?php
  48. use \A\B;
  49. ',
  50. ),
  51. array(
  52. '<?php
  53. $a = function(\B\C $a) use ($b){
  54. };
  55. ',
  56. ),
  57. array(
  58. '<?php
  59. namespace NS;
  60. use A\B;
  61. ',
  62. '<?php
  63. namespace NS;
  64. use \A\B;
  65. ',
  66. ),
  67. array(
  68. '<?php
  69. namespace NS{
  70. use A\B;
  71. }
  72. namespace NS2{
  73. use C\D;
  74. }
  75. ',
  76. '<?php
  77. namespace NS{
  78. use \A\B;
  79. }
  80. namespace NS2{
  81. use \C\D;
  82. }
  83. ',
  84. ),
  85. array(
  86. '<?php
  87. use \C;
  88. use \C\X;
  89. namespace Foo {
  90. use A;
  91. use A\X;
  92. new X();
  93. }
  94. namespace Bar {
  95. use B;
  96. use B\X;
  97. new X();
  98. }
  99. ',
  100. '<?php
  101. use \C;
  102. use \C\X;
  103. namespace Foo {
  104. use \A;
  105. use \A\X;
  106. new X();
  107. }
  108. namespace Bar {
  109. use \B;
  110. use \B\X;
  111. new X();
  112. }
  113. ',
  114. ),
  115. array(
  116. '<?php
  117. namespace Foo\Bar;
  118. use Baz;
  119. class Foo implements Baz {}
  120. ',
  121. '<?php
  122. namespace Foo\Bar;
  123. use \Baz;
  124. class Foo implements Baz {}
  125. ',
  126. ),
  127. );
  128. }
  129. public function provideFix54Cases()
  130. {
  131. return array(
  132. array(
  133. '<?php
  134. trait SomeTrait {
  135. use \A;
  136. }
  137. ',
  138. ),
  139. array(
  140. '<?php
  141. namespace NS{
  142. use A\B;
  143. trait Tr8A{
  144. use \B, \C;
  145. }
  146. }
  147. namespace NS2{
  148. use C\D;
  149. }
  150. ',
  151. '<?php
  152. namespace NS{
  153. use \A\B;
  154. trait Tr8A{
  155. use \B, \C;
  156. }
  157. }
  158. namespace NS2{
  159. use \C\D;
  160. }
  161. ',
  162. ),
  163. array(
  164. '<?php
  165. trait Foo {}
  166. class Bar {
  167. use \Foo;
  168. }
  169. ',
  170. ),
  171. );
  172. }
  173. }